I\'ve been wondering about this one for a while now, so I thought it would be worth using my first Stack Overflow post to ask about it.
Imagine I have a discussion with
Easy; just project onto a POCO (or anonymous) type:
var q = from d in Model.Discussions
select new DiscussionPresentation
{
Subject = d.Subject,
MessageCount = d.Messages.Count(),
};
When you look at the generated SQL, you'll see that the Count() is done by the DB server.
Note that this works in both EF 1 and EF 4.