Retrieve entities with children per one sql call. ADO.NET Entity framework
- by Andrew Florko
Hello everybody,
I have two tables: A & B
B {
B1: Field1,
B2: Field2,
...
}
A
{
Children: List of B,
A1: Field1,
A2: Field2,
}
I want to retrieve "A" entities with related "B" entities like this:
DataContext.A.Select( a = new MySubset( A1 = a.A1, Children = a.Children.Select(b = b.B1).ToList());
But EF can't translate ToList into SQL, so i have to call ToList() per each instance in query producing additional network call.
How can I avoid this?
Thank you in advance.