我在使用include扩展名从1个查询获取所需记录时遇到问题。
这主要是工作:
_db.Companies.Where(x => x.CompanyID == id)
.Include(x => x.Contact)
.Include(x => x.Properties.Select(p => p.Contact))
.Include(x => x.Properties.Select(f => f.Facilities.Select(c => c.Contact)))
.Include(x => x.Properties.Select( => f.Facilities.Select(s => s.Sections.Select(si => si.SectionIdeas))))
.SingleOrDefault();
这很好,除了实体为每个许可证启动一个单独的查询,因为我不包括它。
由于我想在同一个查询中获取许可证,我试过这个:
_db.Companies.Where(x => x.CompanyID == id)
.Include(x => x.Contact)
.Include(x => x.Properties.Select(p => p.Contact))
.Include(x => x.Properties.Select(f => f.Facilities.Select(c => c.Contact)))
.Include(x => x.Properties.Select(f => f.Facilities.Select(l => l.Licenses)))//added
.Include(x => x.Properties.Select(f => f.Facilities.Select(s => s.Sections.Select(si => si.SectionIdeas))))
.SingleOrDefault();
这会导致为每个设施返回另一行。有没有办法在没有额外行的情况下获得许可证?