linq to sql stack overflow with self-referencing entity

时间:2022-09-22 20:50:17

I have an entity that contains many of itself, how do I map this in LINQ to SQl such that it does not do an infinite loop of getting e1 then all its children then their parents (e1) then its children and repeat? Now I know I can do this if I set the child property to false, however that is the most important property (don't really care about the parent). Is there a way to have it do lazy loading? Would that even fix it?

我有一个实体,其中包含许多自身,我如何将它映射到LINQ到SQl,这样它就不会无限循环获得e1然后所有的孩子然后他们的父母(e1)然后它的孩子并重复?现在我知道如果我将child属性设置为false,我可以这样做,但这是最重要的属性(不关心父级)。有没有办法让它进行延迟加载?那会不会修复它?

3 个解决方案

#1


1  

In the designer, select a property on an entity in the diagram, and in the Code Generation section in the properties window, set Delay Loaded to True .

在设计器中,选择图中实体的属性,并在属性窗口的“代码生成”部分中,将“延迟加载”设置为“真”。

See this blog post.

看到这篇博文。

#2


0  

As far as I know LINQ to SQL does lazy loading by default. And even if it doesn't, I'm pretty sure the MS guys used some kind of identity map to ensure every record is loaded only once per DataContext.

据我所知,默认情况下LINQ to SQL会进行延迟加载。即使它没有,我很确定MS人员使用某种身份映射来确保每个DataContext只加载一次记录。

Did you experience it getting stuck in a loop in practice?

你是否经历过它在练习中陷入困境?

#3


-1  

This site is not good for my pre-existing biases, turns out this one was an ill-configured route not lazy/eager loading

这个网站不适合我以前存在的偏见,原来这个是一个配置错误的路线而不是懒惰/渴望加载

#1


1  

In the designer, select a property on an entity in the diagram, and in the Code Generation section in the properties window, set Delay Loaded to True .

在设计器中,选择图中实体的属性,并在属性窗口的“代码生成”部分中,将“延迟加载”设置为“真”。

See this blog post.

看到这篇博文。

#2


0  

As far as I know LINQ to SQL does lazy loading by default. And even if it doesn't, I'm pretty sure the MS guys used some kind of identity map to ensure every record is loaded only once per DataContext.

据我所知,默认情况下LINQ to SQL会进行延迟加载。即使它没有,我很确定MS人员使用某种身份映射来确保每个DataContext只加载一次记录。

Did you experience it getting stuck in a loop in practice?

你是否经历过它在练习中陷入困境?

#3


-1  

This site is not good for my pre-existing biases, turns out this one was an ill-configured route not lazy/eager loading

这个网站不适合我以前存在的偏见,原来这个是一个配置错误的路线而不是懒惰/渴望加载