开发者

Join and batch update in LINQ to SQL

开发者 https://www.devze.com 2023-03-29 07:57 出处:网络
Can something like this be written in LINQ to SQL: UPDATE Table1 SET CustomerName = t2.Name FROM T开发者_开发问答able1 t1 JOIN Table2 t2

Can something like this be written in LINQ to SQL:

UPDATE Table1 
SET CustomerName = t2.Name 
FROM T开发者_开发问答able1 t1 JOIN Table2 t2
ON t1.TableID = t2.TableID  


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消