views:

55

answers:

1

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 about L2E? I tested, looks like in L2E it is not like that. Maybe I did something wrong.

+1  A: 

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.

Nicholas Murray