Entity Key not updating on Insert
Entity Key not updating on Insert
We are using a DB that leverages an insert trigger to populate the primary key upon insert, however Entity Framework is not refreshing the entity with the new Id... Any particular trick to getting this to work?
Thanks.
Thanks.
Set the StoreGeneratedPattern attribute to "Identity" for the primary key column in the Store part of the model.
In case you are using Devart Entity Model, you can just open Model Explorer, go to Model.Store and set the StoreGeneratedPattern property for the primary key column in design time.
In case you are using .edmx model, then you will have to change XML using any XML editor you like. Just add StoreGeneratedPattern="Identity"' to the definition of the Entity Key property in the SSDL part of the model.
In case you are using Devart Entity Model, you can just open Model Explorer, go to Model.Store and set the StoreGeneratedPattern property for the primary key column in design time.
In case you are using .edmx model, then you will have to change XML using any XML editor you like. Just add StoreGeneratedPattern="Identity"' to the definition of the Entity Key property in the SSDL part of the model.
Thanks for responding Audrey. The model is implementde as you suggested, but I am not seeing the expected result. If I insert a record and submit changes, the entity appears in the DB with the appropriate key value, but the enntity client side remains with an ID of zero. If I attempt a subsequent isert, it fails client side as there is a duplicate ID of zero.
Thanks Andrey - your response:
You have not set the StoreGeneratedPattern in the SSDL part of the model.
I have sent you the corrected project back, it works now.
Open the model in the XML Editor, you will see this attrbute set in the SSDL part of the model for the Entity Key property.
Visual Studio ignores setting this attribute in the CSDL part of the model (which takes place when you edit the property in design time), this is a known issue:
http://geeksharp.com/2010/05/27/ef4-bug ... tern-ssdl/
Has indeed corrected the issue for me. Just to clarify for anyone else that wanders by - this is a bug in the EF designer, not DevArt's EF provider.
You have not set the StoreGeneratedPattern in the SSDL part of the model.
I have sent you the corrected project back, it works now.
Open the model in the XML Editor, you will see this attrbute set in the SSDL part of the model for the Entity Key property.
Visual Studio ignores setting this attribute in the CSDL part of the model (which takes place when you edit the property in design time), this is a known issue:
http://geeksharp.com/2010/05/27/ef4-bug ... tern-ssdl/
Has indeed corrected the issue for me. Just to clarify for anyone else that wanders by - this is a bug in the EF designer, not DevArt's EF provider.