A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'ID'

后端 未结 5 999
无人及你
无人及你 2021-01-08 01:13

I can\'t figure out why I get this error when I try to add a Venue object and call SaveChanges(). The only difference in the model with Venue objects is they are 1 to 1..0 r

相关标签:
5条回答
  • 2021-01-08 01:20

    My case was also an incorrectly configured association. Specifically, I had set up a 1..1 relationship when what I needed was a 1..0,1

    0 讨论(0)
  • 2021-01-08 01:32

    I've been suffering with a similar problem. In my case, I'd set up the FK relationship incorrectly and then imported the table with the incorrect FK into my EF model. Despite fixing the FK relationship with the Update Wizard in Visual Studio my correction wasn't picked up.

    To solve this, I deleted the table from the EF model and then re-imported it using the Update Wizard which finally picked up in the change. I hope this helps someone else!

    0 讨论(0)
  • 2021-01-08 01:34

    I found the problem. It was my fault. I had my FK_Venue_City relationship set as City.ID -> Venue.ID where what I wanted was City.ID -> Venue.CityID. I made that change in my database then updated the model.

    0 讨论(0)
  • 2021-01-08 01:36

    OK, adding my experience with this obscure error message:

    I had the same exception and after comparing the database against the EDMX (what a tedious task!!) I found that I mistakenly set a one-to-one relationship the other way around (foreign was primary and primary was foreign).

    Once I fixed that it all worked smoothly!

    Anyway - hopefully my lost 3-4 hours will help someone! :)

    0 讨论(0)
  • 2021-01-08 01:36

    Adding my two bits. I had this error and eventually figured out that I had my parent/child relationship reversed. Once I cleaned up that relationship, it worked again.

    0 讨论(0)
提交回复
热议问题