我正在尝试使用扩展的 Entity Framework 进行批量更新,但我不确定如何执行此操作。
到目前为止,我拥有以下代码:
List<Guid> listIds = new List<Guid>();
listIds = listIds.Union(hem.ProductList.Where(x => x.CustListID == custListID).ToList().Select(y => y.OrderListID)).ToList();
通过上述查询,它返回 1000 个订单列表。
所以我想要实现的目标是: 更新 custListID,其中 OrderListID 在上面的 listIds 中
现在我正在尝试使用扩展的 Entity Framework 。
using (var db = new DBContextEntities())
{
var rowUpdates = db.ProductList.Update(x => x.OrderListID in listIds, x => new ProductList { CustListID = custListID});
}
请告诉我如何实现这一目标。
最佳答案
您正在寻找以下语法:
db.ProductList.Update(x => listIds.Contains(x.OrderListID),
x => new ProductList { CustListID = custListID });
Contains
被转换为 SQL IN
语句。
关于c#-4.0 - 使用EntityFramework.Extended批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19269535/