简体   繁体   中英

C# Linq Joining tables with multi-level

I am trying to query the 3rd level table ef_staff table 3 times to get 3 diff staff objects for each row. How to translate this in LINQ?

SELECT a.a_appraisalid, a.a_year, c.s_staffName, c2.s_staffName, c3.s_staffName
FROM   ef_appraisal a, idp_application b, ef_staff c, ef_staff c2, ef_staff c3
WHERE  a.a_appraisalid = b.a_appraisalid AND
       a.a_staffid = c.s_staffid AND
       a.a_appraisedby = c2.s_staffid AND
       a.a_reviewedby = c3.s_staffid

I have been trying many ways but there is still an error 'Type Inference Failed' in the 2nd & 3rd joining of Staff. What am I missing here?

from application in applications

join appraisal in pmsEntities.ef_appraisal on application.a_appraisalid equals appraisal.a_appraisalid

join staff in pmsEntities.ef_staff on appraisal.a_staffid equals staff.s_staffid

join appraiser in pmsEntities.ef_staff on staff.s_appraisedby equals appraiser.s_staffid into ap

from appraiser in ap.DefaultIfEmpty() 

join reviewer in pmsEntities.ef_staff on staff.s_reviewedby equals reviewer.s_staffid into rv

from reviewer in rv.DefaultIfEmpty() 

join company in pmsEntities.ef_company on appraisal.a_companyid equals company.c_companyid into jc

from company in jc.DefaultIfEmpty()

select appraisal, staff.staffName, appraiser.staffName, reviewer.staffName, company.compName

I fixed the mistake. The first level joining of staff object should be linked to the 2nd level of staff object as below:

join staff in pmsEntities.ef_staff on appraisal.a_staffid equals staff.s_staffid into staffj

                    from staff1 in staffj

                    join appraiser in pmsEntities.ef_staff on staff1.s_appraisedby equals appraiser.s_icno into staff2

`

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM