更新多行Linq与SQL [英] Updating multiple rows Linq vs SQL

查看:55
本文介绍了更新多行Linq与SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我编写了一段代码来更新数据库表中的多行.代码是这样的

Some time ago I wrote a piece of code to update multiple rows in a database table. The code was like this

var db = new MyDataContext();
db.Execute("UPDATE Details SET IsActive = 0 WHERE MasterId = 1");

第二天,当我获得文件的最新版本时,我看到有人将代码更改为类似的内容

Then the other day when I got the latest version of the file I saw that somebody changed the code to something like this

var details = from d in db.details where d.MasterId == 1 select d;
foreach (var detail in details)
  detail.IsActive = false;
db.SubmitChanges();

所以我的问题是:更新多行的更好方法是什么?使用Linq还是SQL?

So my question is: What is the better way to update multiple rows? Using Linq or SQL?

推荐答案

检查本文中使用的方法:

Check the approach used in this article:

这篇关于更新多行Linq与SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆