SaveChanges() in Entity Framework does not retrieve the created Identity key.

.net c# entity-framework identity

Question

I'm using entities Framework in my project and it has been a nightmare!

I have a SQL DB were I have a table called Form.

Form has an ID that is a PK and Identity (it's automatically increased).

This time I'm doing this:

Dim form as int32
Dim dbform As New Entities1
Dim form696 As New Form

dbform.AddToForm696(form)
dbform.SaveChanges()

ID = form.ID

A week ago ID and form.ID had the key generated after insert, but now it only has 0.

I don't know what happened for this to stop working.

I had to change the name of the insert, delete and update stored procedures for several tables and so I had to map this all back again. Maybe I did something wrong but I looked time and time again and everything seems ok.

Does anyone have a clue why?

1
3
12/21/2011 3:03:32 PM

Accepted Answer

I think this issue has been resolved with patches. You should try to remove and add back your Data Model if it still isn't working. EF seems to have less issues with this now.

3
2/15/2010 7:10:09 PM

Popular Answer

ok... I forgot about this

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/12/17/ado-net-entity-framework-tools-stored-procedures.aspx

I had to "use the Result Column Binding, and map the new value to an entity column."

shouldn't Entity Fw do that for me?!



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