EntityFrameWork更新多行

时间:2013-09-26 17:57:53

标签: c# mysql entity-framework entity-framework-4

例如我有这样的表


ID - 分类ID - 产品名称
1 --------- 4 ----------可口可乐
2 --------- 7 ----------茶叶3 --------- 4 ----------精灵

当我在entityframework中编写此代码时:
var list= db.Table.Where(w => w.CategotyID == 4).ToList();
list.ForEach(update => update.ProductName = "Fanta");
db.SaveChanges()我在SQL Profiler中看到执行此语句像这样分开update Table set ProductName = "Fanta" where ID = 1
update Table set ProductName = "Fanta" where ID = 3

如何从SQL写入EntityFrameWork这句话?
update Table set ProductName = "Fanta" where CategoryID = 4

不要让SQL Server单独执行它

1 个答案:

答案 0 :(得分:1)

我不确定,但我认为你做不到。实体框架正在这样做。

也许您可以使用LINGQ to SQL进行尝试。

http://www.codeproject.com/Articles/26657/Simple-LINQ-to-SQL-in-C

相关问题