I want to know how I can include multiple levels of a property for a collection in Entity Framework Core.
An example of my situation:
public class A
{
public ICollection<B> listB ...
}
public class B
{
public C c ...
}
The answers provided in Entity Framework - Include Multiple Levels of Properties for EF Core do not cover the case in which the nested properties are collections, when I try:
var wtv = Context.AItems.Include(a => a.listB).ThenInclude(b => b. )
I only have access to the properties of the ICollection itself (listB) and not the properties of the B objects contained in it, so that I could include the C object in it contained in it.
I managed to do this manually (being a lot more verbose than I would prefer), loading the B objects separately and including what I want in it, and only then add them to A's listB. However, In my real-life situation the properties I want to include in levels below are also for collections so this becomes less and less pratical. Is there a simpler and more elegant way of doing this?