Entity Framework Plus - using InlcudeFilter for muliple level failes

194 views Asked by At

Situation

I have a model "ModelA" where I try to load all properties (several levels) from the database. To avoid loading any properties which will not be necessary I want to work with IncludeFilter, Select and Where.

My current query looks like this:

var query = context.Model_A
    .IncludeFilter(a => a.Model_A1)
    .IncludeFilter(a => a.Model_A2)
    .IncludeFilter(a => a.Model_A3.Select(a3 => a3.Model_B1))
    .AsQueryable();

if (filter == condition) 
{
    query = query.IncludeFilter(a => a.Model_A3
        .Select(a3 => a3.Model_B2.Model_C1
            .Where(c1 => c1.Property_1 == condition)
            .Select(c1 => c1.Model_D1)
    ));
}

The model structure looks like this:

public class Model_A 
{
    public Model_A1 Model_A1
    public int Model_A1_Id

    public Model_A2 Model_A2
    public int Model_A2_Id

    public ICollection<Model_A3> Model_A3
    
    public Model_A() {
        Model_A3 = new Collection<Model_A3>();
    }
}

public class Model_A3 
{
    public Model_B1 Model_B1
    public int Model_B1_Id

    public Model_A Model_A
    public int Model_A_Id

    public Model_B2 Model_B2
    public int Model_B2_Id
}

public class Model_B2 
{
    public ICollection<Model_C1> Model_C1
    
    public Model_B2 {
        Model_C1 = new Collection<Model_C1>();
    }
}

public class Model_C1 
{
    public Model_B2 Model_B2
    public int Model_B2_Id

    public Model_D1 Model_D1
    public int Model_D1_Id
}

Problem

Trying this query I get the following error:

Processing of the LINQ expression 'x => x' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core.

Is this to complicated or do I have just an issue anywhere? Is there a better why to handle this situation?

Any help is appreciated.

0

There are 0 answers