Page 1 of 1

Entity Key not updating on Insert

Posted: Fri 30 Jul 2010 01:08
by DarenM
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.

Posted: Mon 02 Aug 2010 12:48
by AndreyR
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.

Posted: Wed 04 Aug 2010 22:04
by DarenM
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.

Posted: Thu 05 Aug 2010 11:39
by AndreyR
Could you please send me (support * devart * com, subject "EF StoreGeneratedPattern")a test project illustrating the problem?

Posted: Fri 13 Aug 2010 17:13
by DarenM
Any luck looking at the test project to see what I am doing wrong?

Posted: Mon 16 Aug 2010 09:03
by AndreyR
Would you be so kind and resend us the project?
We had a serious problem with our mail server and it seems the letter cannot be restored at our side.
Sorry for the inconvenience.

Posted: Mon 16 Aug 2010 18:07
by DarenM
Just resent the project.

Posted: Mon 16 Aug 2010 21:33
by DarenM
I have sent SQL logs as well. Can you please confirm you have received these emails. Thanks.

Posted: Tue 17 Aug 2010 08:06
by AndreyR
Thank you for the project and logs, we have received them.
I will let you know about the results of our investigation as soon as possible.

Posted: Tue 17 Aug 2010 09:34
by AndreyR
I have replied to you by e-mail.

Posted: Tue 17 Aug 2010 12:51
by DarenM
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.