实体框架 - 调用SaveChanges()没有得到生成的身份密钥密钥、实体、框架、身份

2023-09-05 02:43:15 作者:北悸安凉

我使用实体框架在我的项目,它一直是一个噩梦!

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

我有一个SQL数据库中我有一个名为表格。表格

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

形式所具有的ID,它是一个PK和身份(它会自动增大)。

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

一个星期前ID和form.ID有插入后生成的密钥,但现在它只有0。

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?

推荐答案

我认为这个问题已经解决了补丁。你应该尝试删除并重新添加你的数据模型,如果它仍然是行不通的。 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.