我想將下面的SQL查詢轉換成Linq,但出現一些錯誤。該聯接即使我使用linqr轉換和使用相同的工具查詢工作正常將SQL查詢轉換爲Linq - 錯誤
SQL查詢
Select
pj.JobID,
ja.IsAssigned,
pj.JobUniqueID,
u.FirstName,
pj.IsApproved,
pj.IsActive,
pj.IsQuoted,
pj.IsAssigned,
pj.ApprovalDate,
pj.Description,
s.ServiceName,
st.ServiceTypeName
from jobs pj inner join users u on pj.CustomerUserID=u.UserID
inner join services s on pj.ServiceID = s.ServiceID
inner join service_type st on st.ServiceTypeID = pj.ServiceTypeID
left join (select JobID, IsAssigned from job_assigned) ja on pj.JobID = ja.JobID and ja.IsAssigned =1
left join (select jobid from job_quotes group by jobid having COUNT(1)<3) j on pj.JobID = j.JobID
Linq : This part i am putting it in the c# code
from pj in db.Jobs
join u in db.Users on new { CustomerUserID = pj.CustomerUserID } equals new { CustomerUserID = u.UserID }
join ja in (
(from Job_assigned in db.Job_assigned
select new {
Job_assigned.IsAssigned,
Job_assigned.JobID
}))
on new { pj.JobID, IsAssigned = 1 }
equals new { JobID = Convert.ToInt32(ja.JobID), IsAssigned = (Int64?)Convert.ToInt64(ja.IsAssigned) } into ja_join
from ja in ja_join.DefaultIfEmpty()
join j in (
(from Job_quotes in db.Job_quotes
group Job_quotes by new {
Job_quotes.JobID
} into g
where g.Count() < 3
select new {
JobID = (System.Int32?)g.Key.JobID
})) on new { JobID = pj.JobID } equals new { JobID = Convert.ToInt32(j.JobID) } into j_join
from j in j_join.DefaultIfEmpty()
select new {
JobID = (System.Int32?)pj.JobID,
IsAssigned = (System.Boolean?)ja.IsAssigned,
pj.JobUniqueID,
u.FirstName,
pj.IsApproved,
pj.IsActive,
pj.IsQuoted,
Column1 = pj.IsAssigned,
pj.ApprovalDate,
pj.Description,
pj.Services.ServiceName,
pj.Service_type.ServiceTypeName
}
Error
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.
我收到錯誤就行了上面的LINQ聲明
不工作join ja in (
(from Job_assigned in db.Job_assigned
錯誤信息非常重要,你知道嗎?請提供。此外,當您使用annonymus類型時,所有參數都必須命名。 – CSharpie