【问题标题】:Transform IEnumerable(Of DataRow()) into List(Of Datarow)将 IEnumerable(Of DataRow()) 转换为 List(Of Datarow)
【发布时间】:2019-03-28 20:22:54
【问题描述】:

我有一个DataSet 与两个DataTables 的关系。
这个Dataset 是我在网格中的DataSource
在我的应用程序的其他站点中,我将此DataSource 用作DataTable。该关系允许我使用ChildRelations

我需要一个列表中的所有DataRows。

第一部分是(DTpadreDThijoDataTables):

DS = New DataSet()
DS.Tables.Add(DTpadre.Copy)
DS.Tables.Add(DThijo.Copy)
DS.Relations.Add("PERMISOS", DS.Tables(0).Columns("CORR"), DS.Tables(1).Columns("CORR_PADRE"), False)
gridDetallePerfiles.DataSource = DS.Tables(0)

我尝试的是:

DTprincipal = DirectCast(gridDetallePerfiles.DataSource, DataTable)
Dim obj = (From a As DataRelation In DTprincipal.ChildRelations() Select a.ChildTable.Select())

但是objIEnumerable(Of <strong>DataRow()</strong>)...我想要IEnumerable(Of <strong>Datarow</strong>)

【问题讨论】:

    标签: vb.net linq ienumerable


    【解决方案1】:

    a.ChildTableDataTable
    a.ChildTable.Select() 是对 DataTableSelect() method 的调用,它返回 DataRow 的数组。
    因此结果类型为IEnumerable(Of <em>an array of DataRow</em>)

    如果您想将所有子表的所有行展平为一个集合,请使用SelectMany

    Dim obj = DTprincipal.ChildRelations.Cast(Of DataRelation).SelectMany(Function(r) r.ChildTable.Select())
    

    【讨论】:

    • 它有效!我知道 selectmany 但我尝试替换 r.childtable.select ...不好的尝试。
    猜你喜欢
    • 2012-11-29
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多