详解EFCore中的导航属性(5)

  这个在查询的进程中会分作几个SQL查询而且会将前面查询的功效作为后头查询的部门条件来举办了,待整个查询完毕后再在内存中将这些功效组合到一个query工具中。

  3 ThenInclude用法

  上面的先容完了之后,你应该可以或许大白这个Include的详细寄义和用法了,接着上面的例子,假如WarrantyWarningLevel内里尚有通过外键Id去关联此外实体,这个时候ThenInclude就派上了用场了,理论上只要互相之间成立了这种外键干系就可以一直ThenInClude下去,可是一般环境下不会用到这么巨大的环境,虽然这内里每一个Include也都是作为一个单独的查询来举办的,这个也可以找详细的例子举办试验,这里也贴出一个详细的例子吧。

public async Task<GetRepairContractDetailForSettlementOutput> GetById(Guid id) {             var repairContract = await _repairContractRepository.GetAll()                 .Include(d => d.RepairContractWorkItems)                     .ThenInclude(w => w.Materials)                 .FirstOrDefaultAsync(r => r.Id == id);               if (repairContract == null)                 throw new ValidationException(_localizer["当前维修条约不存在"]);             var vehicleSold = _vehicleSoldRepository.Get(repairContract.VehicleId);             var isTrafficSubsidy = _repairContractManager.IsTrafficSubsidy(repairContract.Id);             var (nextMaintenanceMileage, nextMaintenanceTime) = _repairContractManager.GetNextMaintainInfo(repairContract, vehicleSold);             var result = new GetRepairContractDetailForSettlementOutput() {                 Id = repairContract.Id,                 Code = repairContract.Code,                 CustomerName = repairContract.CustomerName,                 CellPhoneNumber = repairContract.CellPhoneNumber,                 Vin = repairContract.Vin,                 LicensePlate = repairContract.LicensePlate,                 NextMaintenanceTime = nextMaintenanceTime,                 NextMaintenanceMileage = nextMaintenanceMileage,                 LaborFee = repairContract.LaborFee,                 LaborFeeAfter = repairContract.LaborFeeAfter,                 MaterialFee = repairContract.MaterialFee,                 MaterialFeeAfter = repairContract.MaterialFeeAfter,                 OutFee = repairContract.OutFee,                 OtherFee = repairContract.OtherFee,                 TotalFeeAfter = repairContract.TotalFeeAfter,                 ShowIsTrafficSubsidy = isTrafficSubsidy,                 LastMaintenanceTime = vehicleSold.LastMaintenanceTime,                 LastMaintenanceMileage = vehicleSold.LastMaintenanceMileage,                 WorkItems = _mapper.Map<IList<GetRepairContractWorkItemForSettlementOutput>>(repairContract.RepairContractWorkItems)             };             return result;         }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsjfyg.html