将SQL查询转换为LINQ ORDER BY,GROUP BY,COUNT

时间:2018-08-21 02:50:46

标签: sql asp.net-mvc linq lambda

我很难将此查询转换为LINQ。你们能帮我吗?

render()

谢谢!

1 个答案:

答案 0 :(得分:1)

var query = from qNo in QuestionNumber
            join tAnswer in TestAnswer on
            qNo.QNID equals tAnswer.QNID into qAnswer
            group qAnswer by qNo.ChoiceId
            where qNo.QuestionId == 30
            select new { ChoiceId = qNo.ChoiceId, 
                         QCount = qAnswer.Count() }
            orderby qAsnwer.QCount descending