I found that this works to load the "count" property without loading all the objects in the collection:
using (var context = new Entities()) { var people = (from p in c.People select new { Person = p, AddressCount = p.Addresses.Count }).ToList(); foreach (var item in people) { item.Person.AddressCount = item.AddressCount; } }
The disadvantage, of course, is that the AddressCount needs to be configured. I think you could give it an internal setter if your context is in the same assembly as the entity class.
You may not need Include("Addresses") , which is worth checking out. The change has been deleted, as it is not necessary (and may make the request work more than necessary).
source share