ebcrypto
ebcrypto

Reputation: 610

Linq To SQL, Do not SELECT SCOPE_IDENTITY() after INSERT

This is a follow up on the question Stop LINQ to SQL from executing select statements after insert which somehow stayed unanswered.

I'm inserting 10,000 rows in a table, the primary key being auto-generated by SQL server. After inserting the rows, I do not need to post-process them, and the program is closed.

Looking at the LINQ to SQL log, for every INSERT, a consecutive SELECT statement for SCOPE_IDENDITY() is generated. I feel this is slowing down my program, and I would like to get rid of it.

How do I INSERT without the immediate SELECT ?

Upvotes: 3

Views: 1631

Answers (1)

Pleun
Pleun

Reputation: 8920

If you are worried about performance than I am afraid you have to change your approach completely.

Linq to Sql is not suitable for bulkinserts - as you have noticed it inserts them all one by one.

Since you are not post processing them you better use something like SqlBulkCopy. That is magnitudes faster.

Upvotes: 2

Related Questions