简体   繁体   中英

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?

Can you try use this functionality ?

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM