导入命名空间using EntityFramework.Extensions
并使用Update
(来自Update方法描述的示例):
dbContext.Users.Update(
u => u.Email.EndsWith(emailDomain),
u => new User { IsApproved = false, LastActivityDate = DateTime.Now });
context.tblToUpdate
.Update(entry => condition, entryWithnewValues => new tblToUpdate{});
更新为:
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没有特殊要求。