I have this entities:
public class A
{
public List<B> B { get;set; }
}
public class B
{
public DateTime Date { get; set; }
public List<C> C { get; set; }
}
public class C { }
and I need to get C from A where B.Date > DateTime.Now..
I’m trying something like this:
var users = _db.A
.Select(a => new
{
A = a,
B = a.B
.Where(b => b.Date >= DateTime.Now).Select(p => new
{
B = b,
C = b.C
})
})
.AsEnumerable()
.Select(a => a.A)
.ToList();
but C is always null.
How can I get C?
UPDATE
If I set virtual in ‘List C’ it works!!
How can I make this work without setting virtual?
You can try to build the object graph manually. The following will run only a single database query (when the first foreach loop executes, the rest is performed in memory):