Linq To Sql and identity_insert

Posted by Ronnie Overby on Stack Overflow See other posts from Stack Overflow or by Ronnie Overby
Published on 2009-09-02T17:07:29Z Indexed on 2010/03/18 17:31 UTC
Read the original article Hit count: 810

Filed under:
|
|
|
|

I am trying to do record inserts on a table where the primary key is an Identity field.

I have tried calling mycontext.ExecuteCommand("SET identity_insert myTable ON") but this doesn't do any good.

I get an error saying that identity_insert is off when I submit changes.

How can I turn it ON from the c# code before I submit changes?

EDIT

I have read that this is because ExecuteCommand's code gets executed in a different session.

EDIT 2

Is there any way I can execute some DDL to remove the Identity Specification from my C# code, do the inserts, and then turn Identity Specification back on?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET