score:6

Accepted answer

you are right about the projection.

if contact has a navigation property forms you can project:

from c in context.contacts
select new { contact = c, formscount = c.forms.count() }

if not, you'll have to use a subquery:

from c in context.contacts
select new
{
  contact = c, 
  formscount = context.forms.count(f => f.contact_id == c.id)
}

ef will handle both situations in one sql query.


Related Query

More Query from same tag