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

时间秒杀一切 提交于 2020-01-15 12:23:34

问题


I started to get this error after marking an ID column on an entity with DatabaseGeneratedOption.Identity (for some reason EF didn't know it was an identity column and was trying to insert a value on that column).

I found this question: A dependent property in a ReferentialConstraint is mapped to a store-generated column.

However, as far as I can tell, all of my relations are perfectly fine. I checked every single table, and triple checked the tables related to the one on which I added the DatabaseGeneratedOption.Identity to. Even odder, the column mentioned in the error is 'ID' - I don't have any foreign keys where the dependent column is ID. I checked this using the following query, which returned no column named 'ID':

SELECT Tab.TABLE_NAME, Col.Column_Name from 
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab, 
    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col 
WHERE 
    Col.Constraint_Name = Tab.Constraint_Name
    AND Col.Table_Name = Tab.Table_Name
    AND Constraint_Type = 'FOREIGN KEY '

Is there anyway to determine which table has the offending foreign key, if indeed it exists? Is there a query I can run to determine if a column marked as 'Identity' is also the dependent column in a foreign key relationship?

来源:https://stackoverflow.com/questions/26538013/debugging-a-dependent-property-in-a-referentialconstraint-is-mapped-to-a-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!