实体框架 - SaveChanges() 未获取生成的身份密钥

发布于 2024-07-29 00:35:56 字数 458 浏览 6 评论 0原文

我在我的项目中使用实体框架,这真是一场噩梦!

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耶耶耶 2024-08-05 00:35:57

我认为这个问题已经通过补丁解决了。 如果数据模型仍然不起作用,您应该尝试删除并添加回来。 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.

岁月染过的梦 2024-08-05 00:35:57

好吧...我忘了这个

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文