VB运行将LINQ分组为DataTable

时间:2015-06-17 22:15:09

标签: vb.net linq

我正在尝试运行LINQ to datatable,这通常对我有用。这次我正在尝试新的东西,分组并从每组中取出第一行。 questionGroups的类型为IEnumerable(Of Object)。当我在调试器中打开查询时,我看到了一个DataRows集合,每个DataRows都有一个ItemArray,其中列出了我期望的值。如何将此查询运行到DataTable,或者选择我想要的两列并将它们运行到字典中?

  

类型'WhereSelectEnumerableIterator(Of。)上的公共成员'ToTable'   VB $ AnonymousType_0(Of Object,IEnumerable(Of Object)),Object)'不是   找到。

    Dim answerGroup As String = "QuestionSortKey"
    Dim answerNo As String = "AnswerNo"
    Dim surveyDefinitionNo As String = "Pk_SurveyDefinitionNo"

    Dim query = _
        From rows In surveyAnswerKeys.Rows _
        Where rows(answerNo) IsNot Nothing _
        Order By Guid.NewGuid() _
        Group By questionSortKey = rows(answerGroup) _
        Into questionGroups = Group _
        Select questionGroups.First()


    Dim randomAnswerNos As DataTable = query.ToTable

编辑:此问题是此问题的一个分支:VB LINQ - Take one random row from each group

0 个答案:

没有答案