【问题标题】:Batch update using EntityFramework.Extended使用 EntityFramework.Extended 进行批量更新
【发布时间】:2013-10-10 04:00:40
【问题描述】:

我正在尝试使用扩展的实体框架进行批量更新,但我不确定如何执行此操作。

到目前为止,我拥有以下代码:

List<Guid> listIds = new List<Guid>();


listIds = listIds.Union(hem.ProductList.Where(x => x.CustListID == custListID).ToList().Select(y => y.OrderListID)).ToList();

上面的查询返回 1000 个订单列表。

所以我想要实现的目标: 更新上面 listIds 中 OrderListID 的 custListID

现在我正在尝试使用扩展的实体框架。

using (var db = new DBContextEntities())
{
    var rowUpdates = db.ProductList.Update(x => x.OrderListID in listIds, x => new ProductList { CustListID = custListID});
}

请告诉我如何实现这一目标。

【问题讨论】:

  • x => x.OrderListID in listIds 的语法不正确。有没有办法做到这一点? . 'in' 语法不正确

标签: c#-4.0 entity-framework-4 entity-framework-extended


【解决方案1】:

您正在寻找这种语法:

db.ProductList.Update(x => listIds.Contains(x.OrderListID),
                           x => new ProductList { CustListID = custListID });

Contains 被转换为 SQL IN 语句。

【讨论】:

    猜你喜欢
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多