Eager Loading for Predicate Builder

Viewed 26

I have an Entity which has a property which is a list of another entity so I can have them related and using EF Core I have to Include that property for it to be returned with my original Entity. Here is an example:

MyEntity.cs

public class MyEntity {
    public int Id {get; set;}
    
    public List<AnotherEntity> MyList { get; set; }
}

AnotherEntity.cs

public class AnotherEntity {
    public int Id {get; set;}
    
    public string Description { get; set; }
}

So In EF Core I can just do this

_entityContext.MyEntity.Include(x => x.AnotherEntity);

So my question is: Using the PredicateBuilder, is there a way I can tell it to include AnotherEntity in the result?

At the moment, I have AnotherEntity in my DTO which I am mapping from my entity, but its always null and I know in the database it isn't null. I need access to my AnotherEntity data and I cant see many answers online for this so maybe it isn't doable via PredicateBuilder.

Hopefully this question has enough info in it :)

0 Answers
Related