I would like to create a more structured approach to loading the needed entity-tree:
我想创建一个更加结构化的方法来加载所需的实体树:
I need a serious amount of data, so I'm doing this using type-safe Includes (just a normal Include but with Lambda's) as shown here.
我需要大量的数据,所以我使用类型安全的包含(只是一个普通的包含但使用Lambda的),如下所示。
As I said, I need a lot of data, basically a whole entity tree under 1 parent item.
正如我所说,我需要大量数据,基本上是1个父项下的整个实体树。
Now, I could do this doing something like:
现在,我可以这样做:
context.House
.Include(x => x.Doors)
.Include(x => x.Doors.FirstOrDefault().Joint)
.Include(x => x.Doors.FirstOrDefault().Joint.FirstOrDefault().JointCategory)
.Include(x => x.Doors.FirstOrDefault().Joint.FirstOrDefault().JointCategory.JointType)
.Include(x => x.Windows)
// ... same thing
.Include(x => x.Roof)
// ... same thing
As you can see, this line filled with includes can get quite huge. This is in fact a very simplified sample of the actual code (which doesn't include houses btw)
正如你所看到的,这条充满了包含的行可以变得非常庞大。这实际上是一个非常简单的实际代码示例(不包括btw的房子)
So what I would like to do is creating methods, responsible for its branch in the tree. Where the method can accept the object query and include the child, and in its turn, call the "child-loader methods". Also, the parent shouldn't matter, as long as it has a property with the type of the child.
所以我想要做的是创建方法,负责树中的分支。方法可以接受对象查询并包含子进程,然后调用“子加载器方法”。此外,父母应该无关紧要,只要它具有属于孩子类型的属性即可。
This probably does not make much sense so:
这可能没有多大意义:
public void LoadHouse(int id)
{
// ...
ObjectQuery<House> query = context.House;
// and now?
LoadDoors(query, x => x.Door);
}
public void LoadDoors<T>(ObjectQuery<T> query, ..?..)
{
// ... ?
LoadJoints(...)
}
And so on. But I can't really get my head around it... There's a missing link between the incoming query and calling the child methods.
等等。但是我无法理解它...传入的查询和调用子方法之间缺少一个链接。
Has anyone done something like this? Or could anyone give me some pointers?
有没有人做过这样的事情?或者任何人都可以给我一些指示?
1 个解决方案
#1
Try something like this instead:
尝试这样的事情:
query = LoadDoors(query, x => x.Door);
query = LoadDoors(query,x => x.Door);
Where LoadX returns the result of calling Include.
LoadX返回调用Include的结果。
#1
Try something like this instead:
尝试这样的事情:
query = LoadDoors(query, x => x.Door);
query = LoadDoors(query,x => x.Door);
Where LoadX returns the result of calling Include.
LoadX返回调用Include的结果。