I need to retrieve data using EF 4.1 Code first that are contained in several related tables. Currently if i use this
return Context.Set<Entity>()
.Include(x => x.Children.Select(y => y.GrandChildren.Select(z => z.Child)))
.Include(x => x.SomeEntity)
.Include(x => x.AnotherEntity)
.OrderByDescending(x => x.Id)
.FirstOrDefault();
The data is fetched correctly, but I am worried about two things:
1) it seems that there is no way to sort Chilren / GrandChildren
2) the data is flattened in one table, which means that Entity (and all others) data is duplicated for each GrandChild record
Questions:
- What Do I need to do to be able to sort Children / GrandChildren?
- The 2nd point itself may not be a problem in this particular case, since the amount of data that is transferred is not big - max 30 records with 30 columns. Still, I would like to know if there is a way to load Enttity, Children and GrandChildren separately (3 queries), and join them on client site?
Returned resultset needs to be updatable.