IQueryable<Appeal> appeal = Repository.Appeals.Include("Case").Include("Case.Patient").Include("ShipmentAppeals").Where(ap => ap.CaseId == caseID);
IQueryable<ICollection<ShipmentAppeals>> shipmentAppeals = appeal.Select(ap => ap.ShipmentAppeals)
ShipmentAppeals 是 Appeal 和 Shipment 实体之间的关联表。
我想从 Repository.Shipments 中获取那些 ShipmentID 存在于上述 shippingAppeals 集合中的货物。
我写的查询如下。它确实有效,但我想避免 for each 循环:
foreach (ICollection<ShipmentAppeals> sAppealOuter in shipmentAppeals.ToList())
{
foreach (ShipmentAppeals sAppealInner in sAppealOuter)
{
Shipment shipment = Repository.Shipments.First(s => s.ID == sAppealInner.ShipmentID);
caseShipments.Add(shipment);
}
}
}