Entity Framework - SaveChanges() doesn't get the generated Identity key

橙三吉。 提交于 2019-12-10 18:45:42

问题


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:


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.




回答2:


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?!



来源:https://stackoverflow.com/questions/1187175/entity-framework-savechanges-doesnt-get-the-generated-identity-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!