使用LINQ to NHibernate有人知道如何在同一个表达式中使用group by和order by。我不得不按照列表执行该组,然后订购这个,似乎我在这里丢失了所以????
实施例: -
Private function LoadStats(...) ...
Dim StatRepos As DataAccess.StatsExtraction_vwRepository = New DataAccess.StatsExtraction_vwRepository
return (From x In StatRepos.GetAnswers(Question, Questionnaire) _
Group x By xData = x.Data Into Count() _
Select New ChartData
With {.TheData = xData,
.TheValue = xData.Count}
).ToList.OrderBy(Function(x) x.TheData)
End Sub
答案 0 :(得分:1)
我不是Visual Basic专家,但您应该能够在Select
子句中使用别名来创建临时变量,以便您可以在后面的子句中引用它,例如{{1 }}。除非NHibernate有一些限制,否则以下内容应该有效:
Order By
我想在某些情况下,这可能比在return From x In StatRepos.GetAnswers(Question, Questionnaire) _
Group x By xData = x.Data Into Count() _
Select res = New ChartData With _
{ .TheData = xData, _
.TheValue = xData.Count } _
Order By res.TheData _
Select res
子句之前移动Order By
子句更具可读性。