下面将返回建筑物中的所有人员及其所有计算机,这样就可以了。
我想将此更改为仅包含Active == 1的计算机和仅包含ActivityTypeId == 5的ActivityLogs。但如果他们没有,我仍然希望该人返回。
public IQueryable<Person> GetPeople(int BuildingId)
{
return this.ObjectContext.People
.Include("Computers")
.Include("ActivityLog")
.Where(p => p.buildingId == BuildingId && !p.migrated)
.OrderBy(p => p.name);
}
答案 0 :(得分:0)
不幸的是,使用Include
语法无法做到这一点。作为替代方案,您可以单独选择每个实体:
var queryWithAllData = this.ObjectContext
.People
.Select(p => new
{
Person = p,
Computers = p.Computers.Where(c => c.Active == 1),
ActivityLogs = p.ActivityLog.Where(a => a.ActivityTypeId == 5)
});
// Do what you need with the records now that you have all the data.