How could I optimize this Linq query?
public IQueryable GetEquipmentUsageIncludingDispatched(Guid jobID, DateTime dateFrom, DateTime dateTo, string workOrder, int? shift = null, UserAuthorization permissions = null)
 {
 var query =
 from ed in DbContext.EquipmentDispatches
 .Where(e => e.JobID == jobID && e.bActive == true && ((e.StartDate == null || e.StartDate <= dateFrom) && (e.EndDate == null || e.EndDate >= dateTo)))
 from e in DbContext.Equipments.Where(x => x.EquipmentID == ed.EquipmentID)
 from ec in DbContext.EquipmentCategories.Where(x => x.EquipmentCategoryID == e.EquipmentCategoryID)
 from u in DbContext.Units.Where(x => x.UnitID == e.UnitID)
 from eu in DbContext.EquipmentSearchViews
 .Where(e => e.EquipmentDispatchID == ed.EquipmentDispatchID && e.Phase == workOrder && (shift == null || e.Shift == shift) && e.DateUsed >= dateFrom && e.DateUsed <= dateTo && e.IsCorrected == 0 && e.EquipmentUsageIDCorrected == null)
 .DefaultIfEmpty()
 select new
 {
 EquipmentUsageID = eu.EquipmentUsageID,
 EquipmentDispatchID = ed.EquipmentDispatchID,
 EquipmentID = ed.EquipmentID,
 Equipment = e.Description + " - " + e.Name + " - " + ec.Name,
 EquipmentName = e.Name,
 Shift = eu.Shift ?? shift,
 AltID = ed.AltID,
 DateUsed = eu.DateUsed,
 Amount = eu.Amount,
 BillingRate = eu.BillingRate,
 UnitName = u.Name,
 CustomerPO = eu.CustomerPO,
 WorkOrder = eu.Phase ?? workOrder,
 WorkOrderDescription = eu.PhaseDescription,
 TimeSheetID = eu.TimeSheetID,
 TimeSheetName = eu.TimeSheetName,
 DateExported = eu.DateExported,
 bActive = true,
 BillingTemplate = eu.EquipmentBillingTemplate,
 EquipmentBillingID = eu.EquipmentBillingID,
 ReallocatedBy = eu.ReallocatedBy,
 DateReallocated = eu.DateReallocated,
 };

 return
 from eu in query.GroupBy(e => new { e.EquipmentDispatchID, e.EquipmentID, e.EquipmentName, e.Equipment, e.Shift, e.AltID, e.BillingRate, e.UnitName,
 e.CustomerPO, e.WorkOrder, e.WorkOrderDescription, e.EquipmentBillingID, e.BillingTemplate})
 let corrections = (from cor in DbContext.EquipmentSearchViews.Where(e => e.EquipmentDispatchID == eu.Key.EquipmentDispatchID
 && e.DateUsed >= dateFrom && e.DateUsed <= dateTo && e.Shift == eu.Key.Shift && e.Phase == eu.Key.WorkOrder && e.UnitName == eu.Key.UnitName)
 select cor)
 select new EquipmentUsageDto
 {
 EquipmentDispatchID = eu.Key.EquipmentDispatchID,
 EquipmentID = eu.Key.EquipmentID,
 Equipment = eu.Key.Equipment,
 EquipmentName = eu.Key.EquipmentName,
 Shift = eu.Key.Shift,
 AltID = eu.Key.AltID,
 BillingRate = eu.Key.BillingRate,
 UnitName = eu.Key.UnitName,
 CustomerPO = eu.Key.CustomerPO,
 WorkOrder = eu.Key.WorkOrder,
 WorkOrderDescription = eu.Key.WorkOrderDescription,
 BillingTemplate = eu.Key.BillingTemplate,
 EquipmentBillingID = eu.Key.EquipmentBillingID,
 Details = eu.Where(e => e.EquipmentUsageID != null).Select(d => new EquipmentUsageDetailDto
 {
 EquipmentUsageID = d.EquipmentUsageID,
 DateUsed = d.DateUsed,
 Amount = d.Amount,
 TimeSheetID = d.TimeSheetID,
 TimeSheetName = d.TimeSheetName,
 DateExported = d.DateExported,
 bActive = d.bActive,
 ReallocatedBy = d.ReallocatedBy,
 DateReallocated = d.DateReallocated,
 Corrections = corrections.Where(c => c.DateUsed == d.DateUsed).Select(c => new EquipmentUsageCorrectionDto
 {
 CreatedBy = c.CreatedBy,
 DateCreated = c.DateCreated,
 Amount = c.Amount,
 TimeSheetID = c.TimeSheetID,
 TimeSheetName = c.TimeSheetName,
 DateExported = c.DateExported,
 TransactionType = c.EquipmentUsageIDCorrected != null ? "Negation" : ((c.IsCorrected == 1 && c.IsCorrectionResult == 0) || c.ReasonFlag == null) ? "Original" : "Correction",
 IsCorrectionResult = c.IsCorrectionResult == 1,
 GroupID = c.GroupID,
 }).OrderBy(l => l.DateCreated).ThenByDescending(l => l.TransactionType).ToList(),
 }),

 };
 }
이 Linq 쿼리를 어떻게 최적화할 수 있을까요?public IQueryable GetEquipmentUsageIncludingDispatched(Guid jobID, DateTime dateFrom, DateTime dateTo, string workOrder, int? shift = null, UserAuthorization permissions = null) { var query = DbContext.EquipmentDispatches의 ed에서 .Where(e => e.JobID == jobID && e.bActive == true && ((e.StartDate == null || e.StartDate <= dateFrom) && (e.EndDate == null || e.EndDate >= dateTo)))) from e in DbContext.Equipments.Where(x => x.EquipmentID == ed.EquipmentID) from ec in DbContext.EquipmentCategories.Where(x => x.EquipmentCategoryID == e.EquipmentCategoryID) from u in DbContext.Units.Where(x => x.UnitID == e.UnitID) 에서 eu in DbContext.EquipmentSearchViews .Where(e => e.EquipmentDispatchID == ed.EquipmentDispatchID && e.Phase == workOrder && (shift == null || e.Shift == shift) && e.DateUsed >= dateFrom && e.DateUsed <= dateTo && e.IsCorrected == 0 && e.EquipmentUsageIDCorrected == null) .DefaultIfEmpty() 새로 선택 { EquipmentUsageID = eu.EquipmentUsageID, EquipmentDispatchID = ed.EquipmentDispatchID, EquipmentID = ed.EquipmentID, Equipment = e.Description + " - " + e.Name + " - " + ec.Name, 장비 이름 = e.이름, Shift = eu.Shift ?? shift, AltID = ed.AltID, DateUsed = eu.DateUsed, Amount = eu.Amount, 청구율 = eu.청구율, 단위 이름 = u.Name, CustomerPO = eu.CustomerPO, 작업 주문 = eu.Phase ?? 작업 주문, 작업 주문 설명 = eu.PhaseDescription, 작업표ID = eu.TimeSheetID, 작업표이름 = eu.작업표이름, DateExported = eu.DateExported, bActive = true, 청구 템플릿 = eu.EquipmentBillingTemplate, 장비 청구 ID = eu.장비 청구 ID, ReallocatedBy = eu.ReallocatedBy, DateReallocated = eu.DateReallocated, }; 반환 from eu in query.GroupBy(e => new { e.EquipmentDispatchID, e.EquipmentID, e.EquipmentName, e.Equipment, e.Shift, e.AltID, e.BillingRate, e.UnitName, e.CustomerPO, e.WorkOrder, e.WorkOrderDescription, e.EquipmentBillingID, e.BillingTemplate}) let corrections = (from cor in DbContext.EquipmentSearchViews.Where(e => e.EquipmentDispatchID == eu.Key.EquipmentDispatchID && e.DateUsed >= dateFrom && e.DateUsed <= dateTo && e.Shift == eu.Key.Shift && e.Phase == eu.Key.WorkOrder && e.UnitName == eu.Key.UnitName) 선택 cor) 새 장비 사용량Dto 선택 { EquipmentDispatchID = eu.Key.EquipmentDispatchID, EquipmentID = eu.Key.EquipmentID, Equipment = eu.Key.Equipment, 장비 이름 = eu.Key.EquipmentName, Shift = eu.Key.Shift, AltID = eu.Key.AltID, BillingRate = eu.Key.BillingRate, UnitName = eu.Key.UnitName, CustomerPO = eu.Key.CustomerPO, 작업 주문 = eu.Key.WorkOrder, 작업 주문 설명 = eu.Key.작업 주문 설명, 청구 템플릿 = eu.Key.BillingTemplate, 장비 청구 ID = eu.Key.EquipmentBillingID, Details = eu.Where(e => e.EquipmentUsageID != null).Select(d => new EquipmentUsageDetailDto) { EquipmentUsageID = d.EquipmentUsageID, DateUsed = d.DateUsed, Amount = d.Amount, 근무표ID = d.근무표ID, 시간표 이름 = d.시간표 이름, DateExported = d.DateExported, bActive = d.bActive, ReallocatedBy = d.ReallocatedBy, DateReallocated = d.DateReallocated, Corrections = corrections.Where(c => c.DateUsed == d.DateUsed).Select(c => new EquipmentUsageCorrectionDto { CreatedBy = c.CreatedBy, DateCreated = c.DateCreated, Amount = c.Amount, 시간표ID = c.시간표ID, 시간표 이름 = c.시간표 이름, DateExported = c.DateExported, TransactionType = c.EquipmentUsageIDCorrected != null ? "Negation" : ((c.IsCorrected == 1 && c.IsCorrectionResult == 0) || c.ReasonFlag == null) ? "원본" : "수정", IsCorrectionResult = c.IsCorrectionResult == 1, GroupID = c.GroupID, }).OrderBy(l => l.DateCreated).ThenByDescending(l => l.TransactionType).ToList(), }), }; }