一直在搜索使用聚合值對IQueryable進行排序(使用Linq To SQL)的快速示例。通過VB.net中的聚合對IQueryable進行排序
我基本上需要計算幾個派生值(兩個值之間的百分比差異等),並通過這個結果排序。
即
返回rows.OrderBy(功能(S)CalcValue(s.Visitors,s.Clicks))
我想調用外部函數來計算聚合。這應該實現IComparer嗎?或IComparable?
感謝
[編輯] 曾嘗試使用:
Public Class SortByCPC : Implements IComparer(Of Statistic)
Public Function Compare(ByVal x As Statistic, ByVal y As Statistic) As Integer Implements System.Collections.Generic.IComparer(Of Statistic).Compare
Dim xCPC = x.Earnings/x.Clicks
Dim yCPC = y.Earnings/y.Clicks
Return yCPC - xCPC
End Function
End Class
的LINQ to SQL不使用的IComparer
不喜歡我
我不能讓這對LINQ工作要SQL的IQueryable – 2008-12-16 03:55:41