且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环依赖于实体框架

更新时间:2023-02-03 20:44:26

我有一个表,有一个关系到自己和我得到了同样的错误。原来,外键为可以为空。 在实体框架 同桌关系 我希望这样可以节省别人更多的时间比我浪费了。

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


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.