[英]Referential integrity constraint violation occurred
I am getting the following error when calling context.Set<Person>().Attach(person);
调用
context.Set<Person>().Attach(person);
时出现以下错误context.Set<Person>().Attach(person);
on EF 5.0 在EF 5.0上
A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship.
发生参照完整性约束冲突:定义参照约束的属性值在关系中的主体对象和从属对象之间不一致。
Is there some way to figure out which exact property is generating this error? 有什么办法可以找出哪个确切的属性正在产生此错误?
I know what the cause is, that a foreign key which is directly a property of an object is different from the related object's primary key, so for example: 我知道是什么原因,直接是对象属性的外键与相关对象的主键不同,例如:
Person --> Address
ID PersonID
Person
and Address.PersonID
isn't the same as Address.Person.PersonID
, but no matter where I look at my real life object I am not getting which property is causing this. 和
Address.PersonID
与Address.Person.PersonID
,但是无论我在现实生活中的位置如何,都不会知道是哪个属性引起的。
So is there some way to get to the root of the problem, maybe stepping through the ObjectStateManager or some ChangeTracking routine? 那么,是否有某种方法可以解决问题的根源,例如逐步执行ObjectStateManager或某些ChangeTracking例程?
I have already written a t4 template file (to autogenerate it based on my entitymodel) that checks every ForeignKey/PrimaryKey, and I just cannot find a difference. 我已经编写了一个t4模板文件(基于我的entitymodel自动生成它),该文件检查每个ForeignKey / PrimaryKey,但我只是找不到任何区别。
Multi ForeignKey ruined my day... 多ForeignKey毁了我的一天...
So to complete my sample above it was like; 因此,要完成我上面的样本就好了;
Person --> Address
ID PersonID
ID2 PersonID2
Person
And I didnt check the ID2 of my objects, which was loaded incorrectly. 而且我没有检查我的对象的ID2,它的加载不正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.