渴望负荷自引用表 [英] Eager load a self-referencing table
问题描述
我类别
的标准自引用表。在我的实体模型我曾协会孩子
和父
。是否有可能对整个类别
对象不加载延迟加载?
I have a standard self referencing table of Categories
. In my entity model I have made associations Children
and Parent
. Is it possible to load the whole Category
object without lazy loading?
如果我用下面的代码,它加载只到第二级。
if I use the code below, it loads only to the second level.
db.Categories.MergeOption = System.Data.Objects.MergeOption.NoTracking;
var query = from c in db.Categories.Include("Children")
where c.IsVisible == true
orderby c.SortOrder, c.Id
select c;
是,如果我已经加载的所有类对象可以装入引用?
Is it possible to load references if I have all the category objects already loaded?
一个方法来加载它是对孩子
物业多次添加
One method to load it is to add the Children
property multiple times
db.Categories.Include("Children.Children.Children.Children.Children")
但是这会产生一个很长疯了的T-SQL代码,也不会做我想做的。
but this generates a very long insane T-SQL code and also it doesn't do what I want.
推荐答案
没有,这是不可能的。试想一下:所有的LINQ to Entities查询翻译成SQL。其中的SQL语句包括自引用层次无限的深度?在标准的SQL,没有一个。如果有这种在T-SQL的延伸,我不知道它是什么,我不认为EF供应商做,无论是。
No, it isn't possible. Consider: All LINQ to Entities queries are translated into SQL. Which SQL statement includes an unlimited depth in a self-referencing hierarchy? In standard SQL, there isn't one. If there's an extension for this in T-SQL, I don't know what it is, and I don't think EF providers do, either.
这篇关于渴望负荷自引用表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!