开发者

Update a record in L2S and L2E

I was told in L2S, the code for update and insert are the same,

db.InsertOnSubmit(row); 
db.SubmitChanges();

and L2S will check to see if it is a insert or update and act approprately in the background.

Is that true?

How 开发者_Python百科about L2E? I tested, looks like in L2E it is not like that. Maybe I did something wrong.


In 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 Entites uses

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.

There's a comprehensive list of differences between L2S and L2E in this stackoverflow question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜