将sql查询写入实体框架

问题描述:

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框架中做嵌套级查询最后我用了其他方法 –

做同样的

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();