A dependent property in a ReferentialConstraint is mapped to a store-generated column

后端 未结 13 1426
终归单人心
终归单人心 2020-11-27 17:23

I get this error when writing to the database:

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

相关标签:
13条回答
  • 2020-11-27 17:45

    In my case it was simply that I did not have permissions set properly on the database. I had read only set and Entity framework was giving me a ReferentialConstraint error which threw me off. Added additional write permissions and all was well.

    0 讨论(0)
  • 2020-11-27 17:46

    I had the same problem and after some digging in table design in sql server , I found that mistakenly i set table's primary key also as foreign key.

    sql server table design flow

    In this image you can see that JobID is table's primary key but also mistakenly foreign key.

    0 讨论(0)
  • 2020-11-27 17:47

    In my case Id field wich FK just in Entity Framework the propierty "StoreGeneratedPattern" was set "Itentity" instead of "None"

    0 讨论(0)
  • 2020-11-27 17:48

    This error says that you are using unsupported relation or you have error in your mapping. Your code is most probably absolutely unrelated to the error.

    The error means that you have some relation between entities where foreign key property in dependent entity is defined as store generated. Store generated properties are filled in the database. EF doesn't support store generated properties as foreign keys (as well as computed properties in primary keys).

    0 讨论(0)
  • 2020-11-27 17:49

    Is it possible that you defined a bad column relation between your tables? different columns and one was set as autonumeric.

    It happened to me.

    0 讨论(0)
  • 2020-11-27 17:51

    In my case the problem was caused by having a two-way 1-1 relationship:

    class Foo{
    [Key]
    Id
    [ForeignKey]
    BarId
    ...
    }
    class Bar{
    [Key]
    Id
    [ForeignKey]
    FooId
    ...
    }
    

    I had to simply remove one of the two foreign keys (not necessary anyway).

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