【问题标题】:LINQ: query returns list of empty objectsLINQ:查询返回空对象列表
【发布时间】:2012-05-03 15:06:36
【问题描述】:

我有一个“选择”类型对象的查询:

Dim l as IList(Of Foo) = (From dataRow As DataRow In table.Select()
                          Where CStr(dataRow("Column1")) = "A"
                          Select New Foo(CStr(dataRow("Column1")), _
                                         CStr(dataRow("Column2")))).ToList()

发生的情况是,如果我为Foo 的构造函数设置断点并执行步骤,构造函数会被命中,并且参数会加载参数。但是,l 有空的Foo 对象(每个对象中的成员都是Nothing)。这里会发生什么?

【问题讨论】:

  • 听起来Foo 没有将参数的值存储到构造函数中。你也可以发布构造函数吗?

标签: .net vb.net linq linq-to-dataset


【解决方案1】:

将您的查询更改为:

Dim l as IList(Of Foo) = (From dataRow As DataRow In table..AsEnumerable()
                          Where datarow.Field(of String)("Column1") = "A" 
                          Select New Foo(datarow.Field(of String)("Column1"), _
                                         datarow.Field(of String)("Column1"))).ToList()

欲了解更多信息,您可以访问herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2022-08-09
    相关资源
    最近更新 更多