在LINQ to SQL中加入和批量更新

时间:2011-08-19 00:30:08

标签: linq

可以用LINQ to SQL编写这样的东西:

UPDATE Table1 
SET CustomerName = t2.Name 
FROM Table1 t1 JOIN Table2 t2
ON t1.TableID = t2.TableID  

1 个答案:

答案 0 :(得分:2)

var result =  from t1 in context.Table1
              join t2 in context.Table2 on t1.TableID = t2.TableID
              select new {t1, t2};

result.ToList().ForEach(i => i.t1.CustomerName = i.t2.Name);
context.SubmitChanges();