实体框架 - SaveChanges() 未获取生成的身份密钥
我在我的项目中使用实体框架,这真是一场噩梦!
我有一个 SQL 数据库,有一个名为 Form 的表。
Form有一个ID,它是PK和Identity(它是自动增加的)。
这次我这样做:
Dim form as int32
Dim dbform As New Entities1
Dim form696 As New Form
dbform.AddToForm696(form)
dbform.SaveChanges()
ID = form.ID
一周前 ID 和 form.ID 在插入后生成了密钥,但现在它只有 0。
我不知道发生了什么导致它停止工作。
我必须更改几个表的插入、删除和更新存储过程的名称,因此我必须将其全部映射回来。 也许我做错了什么,但我看了一遍又一遍,一切似乎都很好。
有人知道为什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这个问题已经通过补丁解决了。 如果数据模型仍然不起作用,您应该尝试删除并添加回来。 EF 现在似乎在这方面的问题减少了。
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.
好吧...我忘了这个
http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/12/17/ado-net-entity-framework-tools-stored-procedures.aspx< /a>
我必须“使用结果列绑定,并将新值映射到实体列。”
Entity Fw 不应该为我做这件事吗?!
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?!