With EF4 and IDENTITY INSERT

entity-framework identity-insert

Question

I'm attempting to create a database record with a predetermined primary key value. I'm aware of how to accomplish this using SQL, but I'm curious whether EF can do it for me. If not, I will need to develop a stored procedure for the inserts.

1
12
2/15/2011 4:49:51 AM

Accepted Answer

Should you possess theStoreGeneratedPattern Your entity's Entity Key value will be given to the database if attribute is set to "None".

There is no way to control the value that will be assigned to this column in the database if this attribute is set to either "Identity" or "Computed".

Consequently, if your database has an auto-incremented column and the ADO.NET Entity Data Model wizard has specified theStoreGeneratedPattern For your benefit, you may use the XML Editor to manually alter this property in the SSDL portion of the model to "None", and then enableIDENTITY_INSERT .

If you're using EF4, you may use the ObjectContext.ExecuteStoreCommand technique or theObjectContext.Connection.StoreConnection the ability to run a SQL commandSET IDENTITY_INSERT <Your_Table> ON (in EF v4 and EF v1)

12
6/29/2011 12:59:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow