Ronnie Overby
Ronnie Overby

Reputation: 46480

Linq To Sql - How to get # of inserted records

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?

Upvotes: 3

Views: 1035

Answers (2)

craziac
craziac

Reputation: 172

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.

Upvotes: 0

Maksim Kondratyuk
Maksim Kondratyuk

Reputation: 1399

Can you try use this functionality ?

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

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

Upvotes: 4

Related Questions