Entity Key not updating on Insert

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Entity Key not updating on Insert

Post by DarenM » Fri 30 Jul 2010 01:08

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 02 Aug 2010 12:48

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.

DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Post by DarenM » Wed 04 Aug 2010 22:04

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 05 Aug 2010 11:39

Could you please send me (support * devart * com, subject "EF StoreGeneratedPattern")a test project illustrating the problem?

DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Post by DarenM » Fri 13 Aug 2010 17:13

Any luck looking at the test project to see what I am doing wrong?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 16 Aug 2010 09:03

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.

DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Post by DarenM » Mon 16 Aug 2010 18:07

Just resent the project.

DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Post by DarenM » Mon 16 Aug 2010 21:33

I have sent SQL logs as well. Can you please confirm you have received these emails. Thanks.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 17 Aug 2010 08:06

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 17 Aug 2010 09:34

I have replied to you by e-mail.

DarenM
Posts: 8
Joined: Fri 30 Jul 2010 01:05

Post by DarenM » Tue 17 Aug 2010 12:51

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.

Post Reply