This project has moved and is read-only. For the latest updates, please go here.

Id Not Being Saved (Auto Generated Column)

Apr 14, 2016 at 11:55 AM
Edited Apr 14, 2016 at 1:53 PM
The auto generated id column is not being updated after a call to bulkinsert and savechanges as it would be for addrange.

Is there anything I can do about this?

I have tried using KeepIdentity and Default in the SQLBulkCopyOptions with no joy.
Apr 30, 2016 at 8:19 AM
Unfortunately not in easy way - BulkInsert does not support this (but you can achieve this writnig some custom code)
May 5, 2016 at 11:41 AM
Hi Kabu,

I have to insert rows from a file to a table with auto generated id column, but i don´t want use the auto generated id, i need keep the id from the file.

¿Is this posible?

Thanks in advance,
May 6, 2016 at 7:06 AM

I got it using keepidentity option works in my case:

stats.BulkInsert(values, SqlBulkCopyOptions.KeepIdentity);

...and works great!!
Oct 27, 2016 at 11:30 PM
Unfortunately this only works when using SQL Server. Using Postgresql an internal error is thrown about the connection already being open.