Limit child rows in Entity Framework Query
        Posted  
        
            by Jim
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jim
        
        
        
        Published on 2010-03-22T07:46:39Z
        Indexed on 
            2010/03/22
            7:51 UTC
        
        
        Read the original article
        Hit count: 270
        
Hi,
If I have a parent and child modelled relationship. How to I select the parent, and some of the child rows. I cannot seem to do it, and load the parent object.
var query = (
from parent in Parents.Include("Children")
from child in parent.Children
where child.Date == parent.Children.Max(x => x.Date)
select parent);
the problem is that the parent is returned multiple times, not the parent with the children loaded.
Is there any way to populate each of the parents, and include the child rows, but only the ones needed. If I try and navigate again, I get all the children, not just the ones with the latest date.
Thanks
© Stack Overflow or respective owner