3

我已使用 NuGet将EntityFramework.Extended链接)添加到我的项目中。现在我面临一个问题;我如何使用它的Update功能与我的dbContext

4

4 回答 4

8

导入命名空间using EntityFramework.Extensions并使用Update(来自更新方法描述的示例):

dbContext.Users.Update(
         u => u.Email.EndsWith(emailDomain),
         u => new User { IsApproved = false, LastActivityDate = DateTime.Now });
于 2012-12-19T22:43:15.320 回答
2

您为 Update 指定 Where 谓词,如下所示:

context.tblToUpdate
       .Update(entry => condition, entryWithnewValues => new tblToUpdate{});
于 2012-12-19T22:44:13.760 回答
0

更新:

YourDbContext context=new YourDbContext();
//update all tasks with status of 1 to status of 2
context.YourModels.Update(
    t => t.StatusId == 1, 
    t2 => new Task {StatusId = 2});

//example of using an IQueryable as the filter for the update
var yourmodel = context.YourModels.Where(u => u.FirstName == "firstname");
context.YourModels.Update(yourmodel , u => new YourModel {FirstName = "newfirstname"});

您应该有一个继承 DbContext 并具有公共 DbSet 的类,例如:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;

namespace YourNamespace.Models
{
    public class YourDBContext: DbContext
    {
         public DbSet<YourModel> YourModels { get; set; }
    }
}

使用 EntityFramework.Extended 没有什么特别的要求

于 2012-12-19T22:45:28.097 回答
-1

DbContext 上的 Extensions 方法现已消失。

支持的扩展方法仅在 IQueryable 上

在此处输入图像描述

于 2017-07-28T08:41:24.160 回答