Aggregate Root Pending Using Entity Framework

I would like to create a more structured approach for loading the required entity tree:

I need a serious amount of data, so I do this using the type of safe inclusions (only regular Include, but with Lambda) as shown here .

As I said, I need a lot of data, basically the whole tree of objects under one parent element.

Now I could do this by 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 inclusion can become quite huge. This is actually a very simplified sample of actual code (which does not include btw at home)

, , . , , " ". , , .

, , :

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(...)


}

. ... .

- - ? - ?

+3
1

- :

query = LoadDoors (, x = > x.Door);

LoadX Include.

+2

Source: https://habr.com/ru/post/1710352/


All Articles