identity-insert

IDENTITY INSERT and LINQ to SQL

倾然丶 夕夏残阳落幕 提交于 2019-11-27 14:05:40
I have a SQL Server database. This database has a table called Item. Item has a property called "ID". ID is the primary key on my table. This primary key is an int with an increment value of 1. When I attempt to insert the record, I receive an error that says: Cannot insert explicit value for identity column in table 'Item' when IDENTITY_INSERT is set to OFF.". I am attempting to insert records using the following code: public int AddItem(Item i) { try { int id = 0; using (DatabaseContext context = new DatabaseContext()) { i.CreatedOn = DateTime.UtcNow; context.Items.InsertOnSubmit(i); context

SqlBulkCopy Insert with Identity Column

牧云@^-^@ 提交于 2019-11-26 16:24:42
I am using the SqlBulkCopy object to insert a couple million generated rows into a database. The only problem is that the table I am inserting to has an identity column. I have tried setting the SqlBulkCopyOptions to SqlBulkCopyOptions.KeepIdentity and setting the identity column to 0 's, DbNull.Value and null . None of which have worked. I feel like I am missing something pretty simple, if someone could enlighten me that would be fantastic. Thanks! edit To clarify, I do not have the identity values set in the DataTable I am importing. I want them to be generated as part of the import. edit 2

SqlBulkCopy Insert with Identity Column

女生的网名这么多〃 提交于 2019-11-26 04:47:11
问题 I am using the SqlBulkCopy object to insert a couple million generated rows into a database. The only problem is that the table I am inserting to has an identity column. I have tried setting the SqlBulkCopyOptions to SqlBulkCopyOptions.KeepIdentity and setting the identity column to 0 \'s, DbNull.Value and null . None of which have worked. I feel like I am missing something pretty simple, if someone could enlighten me that would be fantastic. Thanks! edit To clarify, I do not have the