views:

294

answers:

2

How can I get the number of records that were inserted?

Is there an easier way, with L2S, than count before and count after and taking the difference?

+2  A: 

Can you try use this functionality ?

_db.GetChangeSet().Inserts.Count();

Where _db - your datacontext and it need to do before sumbit your changes ?

Maksim Kondratyuk
A: 

The db.SubmitChanges does not give you the actual records that were affected by the inserts, deletes and updates to the database. Looking at db.GetChangeSet.Count() does give you the truth. It is only when an error occurs during the SubmitChanges call that the numbers in the GetChangeSet.Count() will differ from the actual situation in the db.

craziac
In the case of an error during submit changes, everything is rolled back, correct?
Ronnie Overby
Yes, according to http://stackoverflow.com/questions/542525/transactionscope-vs-transaction-in-linq2sql
Rafe Lavelle