I am having trouble figuring out how to use .Include()
to be able to access this nested relationship. I tried what seemed like the most direct way but intellisense doesn't populate and when I hand enter the relation there is a compilation error.
I have this db mapped setup
public class W
{
public int WId { get; set; }
public virtual ICollection<T> Ts { get; set; }
}
public class T
{
public int TId { get; set; }
public int WId { get; set; }
public int CId { get; set; }
public virtual W W { get; set; }
public virtual C { get; set; }
}
public class C
{
public int CId { get; set; }
public virtual ICollection<T> Ts { get; set; }
}
I have a get method which queries
//set in constructor
DbSet<W> dbSet;
DbContext context;
//called in method
IQueryable<W> query = dbSet;
query = query.Include(w => w.Ts);//works
query = query.Include(w => w.Ts.C); //I wanted to do this but it doesn't work
Can I use .Include()
like this?
It seemed like it was going to work with no hitch but apparently I am doing it wrong. I would prefer not to have to iterate through the Ts collection and then populate their C manually each time.