2

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
4

1 回答 1

1

我修正了错误。员工对象的第一级加入应该链接到员工对象的第二级,如下所示:

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

`

希望能帮助到你

于 2012-12-12T13:25:29.460 回答