[英]Update a record in L2S and L2E
I was told in L2S, the code for update and insert are the same, 在L2S中有人告诉我,更新和插入的代码是相同的,
db.InsertOnSubmit(row);
db.SubmitChanges();
and L2S will check to see if it is a insert or update and act approprately in the background. L2S会检查它是否是插入或更新,并在后台采取适当措施。
Is that true? 真的吗?
How about L2E? L2E呢? I tested, looks like in L2E it is not like that.
我测试过,看起来在L2E中不是那样。 Maybe I did something wrong.
也许我做错了。
In LINQ to SQL 在LINQ to SQL中
InsertOnSubmit()
'Adds an entity in a pending insert state to this Table.' “将处于挂起插入状态的实体添加到此表中。”
Whereas 鉴于
SubmitChanges()
' Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database .' “ 计算要插入,更新或删除的一组修改对象,并执行适当的命令以实现对数据库的更改 。”
So Linq to SQL tracks your changes and then uses SubmitChanges to create the neccessary transactions which will commit the changes to your database. 因此,Linq to SQL会跟踪您的更改,然后使用SubmitChanges创建必要的事务,该事务会将更改提交到您的数据库。
LINQ to Entites uses LINQ to Entites使用
SaveChanges()
as the objects in Linq to Entites are not using a lock against the record in the database and so need to be saved rather than the changes submitted. 因为Linq to Entites中的对象未使用对数据库中记录的锁定,因此需要保存而不是提交更改。
There's a comprehensive list of differences between L2S and L2E in this stackoverflow question . 在这个stackoverflow 问题中 ,有L2S和L2E之间的差异的完整列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.