Improvement: Simplify JobTable SQL Generation
New EF expressions which simplify SQL and avoid some strange behaviour on SQL Express.
This commit is contained in:
@@ -120,16 +120,14 @@ namespace Disco.Services
|
|||||||
if (model.ShowStatus || model.ShowLastActivityDate)
|
if (model.ShowStatus || model.ShowLastActivityDate)
|
||||||
{
|
{
|
||||||
|
|
||||||
var jobItems = Jobs.Select(j => new JobTableStatusItemModel()
|
var jobData = Jobs.Select(j => new
|
||||||
{
|
{
|
||||||
JobId = j.Id,
|
JobId = j.Id,
|
||||||
OpenedDate = j.OpenedDate,
|
OpenedDate = j.OpenedDate,
|
||||||
ClosedDate = j.ClosedDate,
|
ClosedDate = j.ClosedDate,
|
||||||
JobTypeId = j.JobTypeId,
|
JobTypeId = j.JobTypeId,
|
||||||
JobTypeDescription = j.JobType.Description,
|
JobTypeDescription = j.JobType.Description,
|
||||||
DeviceSerialNumber = j.Device.SerialNumber,
|
Device = j.Device,
|
||||||
DeviceProfileId = j.Device.DeviceProfileId,
|
|
||||||
DeviceModelId = j.Device.DeviceModelId,
|
|
||||||
DeviceModelDescription = j.Device.DeviceModel.Description,
|
DeviceModelDescription = j.Device.DeviceModel.Description,
|
||||||
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress,
|
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress,
|
||||||
UserId = j.UserId,
|
UserId = j.UserId,
|
||||||
@@ -139,37 +137,71 @@ namespace Disco.Services
|
|||||||
DeviceHeldLocation = j.DeviceHeldLocation,
|
DeviceHeldLocation = j.DeviceHeldLocation,
|
||||||
Flags = j.Flags,
|
Flags = j.Flags,
|
||||||
|
|
||||||
JobMetaWarranty_ExternalReference = j.JobMetaWarranty.ExternalReference,
|
JobMetaWarranty = j.JobMetaWarranty,
|
||||||
JobMetaWarranty_ExternalLoggedDate = j.JobMetaWarranty.ExternalLoggedDate,
|
JobMetaNonWarranty = j.JobMetaNonWarranty,
|
||||||
JobMetaWarranty_ExternalCompletedDate = j.JobMetaWarranty.ExternalCompletedDate,
|
|
||||||
JobMetaNonWarranty_RepairerLoggedDate = j.JobMetaNonWarranty.RepairerLoggedDate,
|
|
||||||
JobMetaNonWarranty_RepairerCompletedDate = j.JobMetaNonWarranty.RepairerCompletedDate,
|
|
||||||
JobMetaNonWarranty_AccountingChargeAddedDate = j.JobMetaNonWarranty.AccountingChargeAddedDate,
|
|
||||||
JobMetaNonWarranty_AccountingChargePaidDate = j.JobMetaNonWarranty.AccountingChargePaidDate,
|
|
||||||
JobMetaNonWarranty_AccountingChargeRequiredDate = j.JobMetaNonWarranty.AccountingChargeRequiredDate,
|
|
||||||
JobMetaNonWarranty_IsInsuranceClaim = j.JobMetaNonWarranty.IsInsuranceClaim,
|
|
||||||
JobMetaInsurance_ClaimFormSentDate = j.JobMetaInsurance.ClaimFormSentDate,
|
JobMetaInsurance_ClaimFormSentDate = j.JobMetaInsurance.ClaimFormSentDate,
|
||||||
JobMetaNonWarranty_InvoiceReceivedDate = j.JobMetaNonWarranty.InvoiceReceivedDate,
|
|
||||||
JobMetaNonWarranty_PurchaseOrderRaisedDate = j.JobMetaNonWarranty.PurchaseOrderRaisedDate,
|
|
||||||
JobMetaNonWarranty_PurchaseOrderSentDate = j.JobMetaNonWarranty.PurchaseOrderSentDate,
|
|
||||||
|
|
||||||
RecentAttachmentDate = j.JobAttachments.Max(ja => ja.Timestamp),
|
RecentAttachmentDate = (DateTime?)j.JobAttachments.Max(ja => ja.Timestamp),
|
||||||
RecentLogDate = j.JobLogs.Max(jl => jl.Timestamp),
|
RecentLogDate = (DateTime?)j.JobLogs.Max(jl => jl.Timestamp),
|
||||||
|
|
||||||
WaitingForUserAction = j.WaitingForUserAction,
|
WaitingForUserAction = j.WaitingForUserAction,
|
||||||
DeviceReadyForReturn = j.DeviceReadyForReturn,
|
DeviceReadyForReturn = j.DeviceReadyForReturn,
|
||||||
DeviceHeld = j.DeviceHeld,
|
DeviceHeld = j.DeviceHeld,
|
||||||
DeviceReturnedDate = j.DeviceReturnedDate,
|
DeviceReturnedDate = j.DeviceReturnedDate,
|
||||||
JobMetaWarranty_ExternalName = j.JobMetaWarranty.ExternalName,
|
|
||||||
JobMetaNonWarranty_RepairerName = j.JobMetaNonWarranty.RepairerName,
|
JobQueues = j.JobQueues.Where(jq => !jq.RemovedDate.HasValue)
|
||||||
ActiveJobQueues = j.JobQueues.Where(jq => !jq.RemovedDate.HasValue).Select(jq => new JobTableStatusQueueItemModel()
|
}).ToList();
|
||||||
|
|
||||||
|
var jobItems = jobData.Select(j => new JobTableStatusItemModel()
|
||||||
|
{
|
||||||
|
JobId = j.JobId,
|
||||||
|
OpenedDate = j.OpenedDate,
|
||||||
|
ClosedDate = j.ClosedDate,
|
||||||
|
JobTypeId = j.JobTypeId,
|
||||||
|
JobTypeDescription = j.JobTypeDescription,
|
||||||
|
DeviceSerialNumber = j.Device?.SerialNumber,
|
||||||
|
DeviceProfileId = j.Device?.DeviceProfileId,
|
||||||
|
DeviceModelId = j.Device?.DeviceModelId,
|
||||||
|
DeviceModelDescription = j.DeviceModelDescription,
|
||||||
|
DeviceAddressId = j.DeviceAddressId,
|
||||||
|
UserId = j.UserId,
|
||||||
|
UserDisplayName = j.UserDisplayName,
|
||||||
|
OpenedTechUserId = j.OpenedTechUserId,
|
||||||
|
OpenedTechUserDisplayName = j.OpenedTechUserDisplayName,
|
||||||
|
DeviceHeldLocation = j.DeviceHeldLocation,
|
||||||
|
Flags = j.Flags,
|
||||||
|
|
||||||
|
JobMetaWarranty_ExternalReference = j.JobMetaWarranty?.ExternalReference,
|
||||||
|
JobMetaWarranty_ExternalLoggedDate = j.JobMetaWarranty?.ExternalLoggedDate,
|
||||||
|
JobMetaWarranty_ExternalCompletedDate = j.JobMetaWarranty?.ExternalCompletedDate,
|
||||||
|
JobMetaNonWarranty_RepairerLoggedDate = j.JobMetaNonWarranty?.RepairerLoggedDate,
|
||||||
|
JobMetaNonWarranty_RepairerCompletedDate = j.JobMetaNonWarranty?.RepairerCompletedDate,
|
||||||
|
JobMetaNonWarranty_AccountingChargeAddedDate = j.JobMetaNonWarranty?.AccountingChargeAddedDate,
|
||||||
|
JobMetaNonWarranty_AccountingChargePaidDate = j.JobMetaNonWarranty?.AccountingChargePaidDate,
|
||||||
|
JobMetaNonWarranty_AccountingChargeRequiredDate = j.JobMetaNonWarranty?.AccountingChargeRequiredDate,
|
||||||
|
JobMetaNonWarranty_IsInsuranceClaim = j.JobMetaNonWarranty?.IsInsuranceClaim,
|
||||||
|
JobMetaInsurance_ClaimFormSentDate = j.JobMetaInsurance_ClaimFormSentDate,
|
||||||
|
JobMetaNonWarranty_InvoiceReceivedDate = j.JobMetaNonWarranty?.InvoiceReceivedDate,
|
||||||
|
JobMetaNonWarranty_PurchaseOrderRaisedDate = j.JobMetaNonWarranty?.PurchaseOrderRaisedDate,
|
||||||
|
JobMetaNonWarranty_PurchaseOrderSentDate = j.JobMetaNonWarranty?.PurchaseOrderSentDate,
|
||||||
|
|
||||||
|
RecentAttachmentDate = j.RecentAttachmentDate,
|
||||||
|
RecentLogDate = j.RecentLogDate,
|
||||||
|
|
||||||
|
WaitingForUserAction = j.WaitingForUserAction,
|
||||||
|
DeviceReadyForReturn = j.DeviceReadyForReturn,
|
||||||
|
DeviceHeld = j.DeviceHeld,
|
||||||
|
DeviceReturnedDate = j.DeviceReturnedDate,
|
||||||
|
JobMetaWarranty_ExternalName = j.JobMetaWarranty?.ExternalName,
|
||||||
|
JobMetaNonWarranty_RepairerName = j.JobMetaNonWarranty?.RepairerName,
|
||||||
|
ActiveJobQueues = j.JobQueues?.Where(jq => !jq.RemovedDate.HasValue).Select(jq => new JobTableStatusQueueItemModel()
|
||||||
{
|
{
|
||||||
Id = jq.Id,
|
Id = jq.Id,
|
||||||
QueueId = jq.JobQueueId,
|
QueueId = jq.JobQueueId,
|
||||||
AddedDate = jq.AddedDate,
|
AddedDate = jq.AddedDate,
|
||||||
SLAExpiresDate = jq.SLAExpiresDate,
|
SLAExpiresDate = jq.SLAExpiresDate,
|
||||||
Priority = jq.Priority
|
Priority = jq.Priority
|
||||||
})
|
}).ToList() ?? Enumerable.Empty<JobTableStatusQueueItemModel>()
|
||||||
});
|
});
|
||||||
|
|
||||||
items = new List<JobTableItemModel>();
|
items = new List<JobTableItemModel>();
|
||||||
|
|||||||
Reference in New Issue
Block a user