2017-09-08 150 views
-3
select * 
from [InterViewerComment] 
where commentID in (select max(commentID) as commentID 
        from [InterViewerComment] 
        where jobID = 45 
        group by qenID) 

該查詢在SQL中是正確的,但我想在實體框架中重寫它。 基本上我想根據工作ID爲每個qenID最新評論。將sql查詢寫入實體框架

+0

到目前爲止你做了什麼? LINQ? – w0051977

+0

不知道如何在Entity框架中做嵌套級查詢最後我用了其他方法 –

回答

0

做同樣的

VAR的查詢= 「選擇qendidateList.qenName,InterViewerComment。*,candidate_status.status,0作爲ExamMarks,0從[InterViewerComment]技能」 其他方式+ 「左外連接qendidateList在InterViewerComment.qenID = qendidateList.qenID「+ 」InterViewerComment.candidate_status = candidate_status.Candidate_status上的左外連接candidate_status「+ 」其中commentID在(從InterViewerComment中選擇max(commentID)作爲commentID,其中jobID = 45 group by qenID )「;

 var CandidateComm_ = db.Database.SqlQuery<interViewerComment>(query).ToList();