实体框架中的循环依赖 [英] circular dependency in entity framework
问题描述
是否可以保存具有循环依赖性的模型?
Is it possible to save model which has got circular dependency ?
我对我的数据库进行非规范化:
I denormalized my Database:
User
--------
UserId
UserName
LastOrder - fk to last order
Order
-------
OrderId
OrderName
UserId
OrderDate
是否可以使用entityFramework保存sth?
Is it possible to save sth like this using entityFramework?
它的工作原因现在我有错误:
what should I change to make it work cause now I have got error:
无法确定依赖操作的有效排序。
由于外键约束,模型
要求或存储生成值,可能存在依赖关系。
Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.
推荐答案
我有一张与自己有关系的表,我得到了同样的错误。结果外键必须为空。
实体框架中的表格关系相同
我希望这样可以节省人们比浪费时间更多的时间。
I had a table that had a relationship to itself and i was getting the same error. Turns out the foreign key has to be nullable. Same table relationship in Entity Framework I hope this saves someone more time than I wasted.
这篇关于实体框架中的循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!