以下の SQL クエリを Linq に変換しようとしていますが、エラーが発生します。変換にlinqrを使用しているにもかかわらず、結合が機能せず、同じツールでクエリが正常に機能しています
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