我正在寻找一种直接从 Linq 到 SQL 查询返回名称值对列表的方法,而不必像我在下面的代码中那样循环遍历结果:
Public Shared Function GetUserTransactionCounts(fromDate As DateTime, toDate As DateTime) As List(Of KeyValuePair(Of String, Integer))
Using dc As New ProntoDataContext()
Dim users As IEnumerable(Of User) = From u In dc.Users Where u.CreatedTransactions.Any(Function(t) t.TSCreate >= fromDate And t.TSCreate <= toDate)
Dim list As New List(Of KeyValuePair(Of String, Integer))
For Each user As User In users
Dim item As New KeyValuePair(Of String, Integer)(user.CommonName, user.CreatedTransactions.Count)
list.Add(item)
Next
Return list
End Using
End Function