在linq中填充列表选择新的

时间:2012-03-13 10:31:53

标签: .net vb.net linq

我有两个班级:

Public Class Result

    Public Property DateInserted As Date

    Public Property Name As String

End Class

Public Class ResultGroup

    Public Property DateInserted As Date

    Public Property Name As String

    Public Property Results As List(Of Result)

End Class

使用以下代码,我试图获得带有结果的ResultGroup列表:

Return (From crg In ctx.CalculationResultGroup
            Select _
                New ResultGroup() _
                    With {.DateInserted = crg.DateInsert, .Name = crg.Name, .Results = (From cr In ctx.CalculationResult
                        Where cr.CalculationResultGroupId = crg.CalculationResultGroupId
                        Select New Result() With {.DateInserted = cr.DateInsert, .Name = cr.Calculation.Name}).ToList}).
        ToList()

当我运行此代码时,我收到以下错误:

  

LINQ to Entities无法识别方法'System.Collections.Generic.List`1 [GridDragDropDemo.Result] ToListResult'方法,并且此方法无法转换为商店表达式。

任何人都可以指出我做错了什么,或者我正在尝试的是根本不可能做到的?

0 个答案:

没有答案