0

在以下实体服务条目的应用程序的列表页面中,我需要显示所有服务条目并包括 ServiceTechnicanID 列,该列有时为 NULL。当它为 NULL 时,我显示一个 NA。直到此时,查询才会提取正确的记录。在查询中提供搜索过滤器时会出现此问题。如果我传入搜索过滤器以按技术人员 ID/全名搜索服务条目,我将获得所有记录。

ServiceEntry
ID
TechnicanID
ServiceTechnicianID

User
ID
FirstName
LastName
FullName (DBComputedColumn)

询问

   var list = (from se in db.ServiceEntry
                        join u in db.User on se.ServiceTechnician equals u.ID into joinUserEntry
                        from u2 in joinUserEntry.DefaultIfEmpty()
                        join r in db.RunLogEntry on se.RunLogEntryID equals r.ID into joinRunLogEntry
                        from r2 in joinRunLogEntry.DefaultIfEmpty()
                        join s in db.System1 on se.SystemID equals s.ID
                        join p in db.Platform1 on s.PlatformID equals p.ID
                        where (
                            ((se.RunLogEntryID == 0 || se.RunLogEntryID != null))
                                 && ((serviceEntryFilter.ID.HasValue == false) || (se.ID == serviceEntryFilter.ID.Value && serviceEntryFilter.ID.HasValue == true))
                                && ((serviceEntryFilter.ServiceDateTime.HasValue == false) || (EntityFunctions.TruncateTime(se.ServiceDateTime) == EntityFunctions.TruncateTime(serviceEntryFilter.ServiceDateTime) && serviceEntryFilter.ServiceDateTime.HasValue == true))
                                && ((serviceEntryFilter.RunDate.HasValue == false) || (EntityFunctions.TruncateTime(r2.RunDate) == EntityFunctions.TruncateTime(serviceEntryFilter.RunDate) && serviceEntryFilter.RunDate.HasValue == true))
                            //&& ((serviceEntryFilter.ServiceTechnician == null) ||   (u2.FullName.Contains(serviceEntryFilter.ServiceTechnician.Trim()) && serviceEntryFilter.ServiceTechnician != null))
                                && ((serviceEntryFilter.ServiceTechnician == null) || ((u2.FullName.Contains(serviceEntryFilter.ServiceTechnician.Trim()))))
                                && (
                                        ((ServiceEntryStatus == "O" && se.ServiceRequestClosed == false) ||
                                          (ServiceEntryStatus == "C" && se.ServiceRequestClosed == true) ||
                                          (ServiceEntryStatus == "A")
                                        )
                                   )
                                       && (
                                        ((ServiceEntryReliabilityRecord == null) ||
                                         (ServiceEntryReliabilityRecord == "N" && se.ReliabilityRecord == false) ||
                                          (ServiceEntryReliabilityRecord == "Y" && se.ReliabilityRecord == true) ||
                                          (ServiceEntryReliabilityRecord == "A")
                                        )
                                    )
                                && (
                                        ((ServiceEntryReconciled == null) ||
                                         (ServiceEntryReconciled == "N" && se.Reconciled == false) ||
                                          (ServiceEntryReconciled == "Y" && se.Reconciled == true) ||
                                          (ServiceEntryReconciled == "A")
                                        )
                                    )
                                             && (
                                        ((ActiveServiceEntry == null) ||
                                         (ActiveServiceEntry == "N" && se.Active == false) ||
                                          (ActiveServiceEntry == "Y" && se.Active == true) ||
                                          (ActiveServiceEntry == "A")
                                        )
                                    )

                                        && (
                                      (s.PlatformID == platformID) || (platformID == 0)
                                   )
                                                                                  && ((serviceEntryFilter.System == null) || (systems.Contains(s.SystemFullName)))

                            )
                        orderby se.ID descending
                        select new ServiceSearchEntry()
                        {
                            ID = se.ID,
                            ServiceDateTime = se.ServiceDateTime,
                            Technician = (u2.FullName == null ? "N/A" : u2.FullName),
                            System = s.SystemFullName,
                            ReasonForFailure = se.ReasonForFailure,
                            RunDate = (r2 == null ? (DateTime?)null : r2.RunDate),
                            Platform = p.PlatformName
                        });
4

0 回答 0