我有以下查询:
var MyQuery = from e in ContractContext.Equipments.Include("Manufacturers")
where e.Customers.ID == customer.ID
select e;
一切正常,我得到了我的设备,它正确(急切地)加载了制造商表。但是当我尝试执行以下多对多查询时:
var MyQuery = from e in ContractContext.Equipments.Include("Manufacturers")
where e.Customers.ID == customer.ID
from cce in e.ContractEquipments
where cce.Contracts.EndedOn >= DateTime.Today
select e;
其中 "ContractEquipments" 是 "Equipments" 和 "Contracts" 之间的多对多查找,但是当此查询运行时,不再容易加载制造商表。知道如何在不执行以下操作的情况下解决此问题:
if (MyEntity.Manufacturers.IsLoaded == false)
MyEntity.ManufacturersReference.Load()
这个项目需要几个小时执行,我想减少数据库调用的数量。
编辑#1:
我也试过这个没有成功:
var MyQuery = from e in ContractContext.Equipments.Include("Manufacturers")
where e.Customers.ID == customer.ID
join cce in ContractContext.ContractEquipments
on e.ID equals cce.Equipments.ID
where cce.Contracts.EndedOn >= DateTime.Today
select e;