我知道此错误在here中给出了答案。但就我而言,我不是直接投影任何文档。当我使用内部联接而不是user
集合中的左联接时,此方法工作正常。 SO的任何内容对我都不起作用
var query = from
his in levelsOfApprovalHistory
where his.ReferenceNo == referenceNumber
join serv in services on his.Service.ServiceId equals serv.ServiceId
join st in status on his.StatusDetails.StatusId equals st.StatusValue
join us in user on his.User.PoliceId equals us.PoliceId into u
from usr in u.DefaultIfEmpty()
join emp in employee on usr.Employee.EmployeeID equals emp.EmployeeID into ps
from p in ps.DefaultIfEmpty()
select new ApplicationStatusHistoryDTO()
{
ID = his.ID,
ReferenceNo = his.ReferenceNo,
Comments = his.Comments,
RequestorNameEn = his.RequestorNameEn,
RequestorNameAr = his.RequestorNameAr,
UTCDate = his.UTCDate,
Service = new Service()
{
ServiceId = his.Service.ServiceId,
ServiceName = serv.ServiceName,
ServiceNameAr = serv.ServiceNameAr
},
StatusDetails = new FollowUpStatus()
{
StatusId = st.StatusId,
StatusNameEn = st.StatusNameEn,
StatusNameAr = st.StatusNameAr,
StatusValue = st.StatusValue,
StyleClass = st.StyleClass,
IsPrimary = st.IsPrimary
},
EmployeeDetails = new Employee()
{
EmployeeID = p.EmployeeID,
FirstName = p.FirstName,
EnglishName = p.EnglishName,
UserCode = usr.MilitaryNumber
},
Level = new Levels()
{
LevelID = his.Level.LevelID,
LevelEnName = his.Level.LevelEnName,
LevelArName = his.Level.LevelArName,
Service = new Service()
{
ServiceId = his.Level.Service.ServiceId
},
IsFinal = his.Level.IsFinal
}
};