且构网

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

LINQ to SQL的:自引用的实体 - PARENTID / ChildID协会

更新时间:2023-02-03 07:54:26

错误,如果你试图获取父实体时,它其实并没有一个家长会发生。您所指定的一切是完全没有问题,我已经实现了类似的关系多次。

The error will happen if you are attempting to get the Parent for an entity when it in fact does not have a Parent. Everything you have specified is perfectly fine and I have implemented similar relationships many times.

您提到一个异常,但是当它发生时你没有提到。在更新过程中?或许有一个FK违规行为?在一个INSERT?或者只是一个查询?

You mentioned an exception but you did not mention when it occurs. During an update? Perhaps there is a FK violation? During an INsert? Or just a query?

Task.Parent.Parent.Parent.Parent是不是你可以做无限的东西。当然它会编译时,code不知道,有数据备份的发言。但在运行时,每个.Parent呼叫需要由一个等效PARENTID列匹配

Task.Parent.Parent.Parent.Parent is not something you can just do infinitely. Sure it will compile, the code doesn't know that there is data backing up that statement. But at runtime, each .Parent call needs to be matched by an equivalent ParentID column.