how to select specific number of child entities instead of all in entity framework 3.5?
Posted
by Sasha
on Stack Overflow
See other posts from Stack Overflow
or by Sasha
Published on 2010-06-17T20:43:36Z
Indexed on
2010/06/17
22:33 UTC
Read the original article
Hit count: 163
entity-framework
|linq-to-entities
Hi all,
i am wondering how can i select specific number of child objects instead of taking them all with include?
lets say i have object 'Group' and i need to select last ten students that joined the group.
When i use '.Include("Students"), EF includes all students. I was trying to use Take(10), but i am pretty new to EF and programming as well, so i couldn't figure it out. Any suggestions?
UPDATED:
ok, i have Group object already retrieved from db like this:
Group group = db.Groups.FirstOrDefault(x=>x.GroupId == id)
I know that i can add Include("Students")
statement, but that would bring ALL students, and their number could be quite big whether i need only freshest 10 students. Can i do something like this: var groupWithStudents = group.Students.OrderByDescending(//...).Take(10);
?
The problem with this is that Take<> no longer appears in intellisense. Is this clear enough? Thanks for responses
© Stack Overflow or respective owner