这样的代码:EF:避免多次更新语句
var compIds = from p in packinglist.List
select p.ComponentId;
var components = from c in context.Components
where compIds.Contains(c.Id)
select c;
foreach (var item in components)
{
item.CurrentSiteId = packinglist.DestinationId;
}
context.SaveChanges();
最终发行大量的SQL语句像
update [dbo].[Components] set [CurrentSiteId] = @0 where ([Id] = @1)
有没有一种方法来指示EF(代码优先)发出以下声明:
update [dbo].[Components] set [CurrentSiteId] = @0 where ([Id] in (....))
或者我应该考虑使用可用的SQLQuery方法之一或单独的工具li小巧或大量或...?
我对这个答案也很感兴趣,但是根据我对EF的经验,这看起来像是一个SQL查询或存储过程(您可以导入到EF中)的候选人。 – Tridus
@Tridus:你应该将它作为答案发布,因为没有其他方式,那么直接使用SQL即可。 –