简体   繁体   English

LINQ:查询返回空对象的列表

[英]LINQ: query returns list of empty objects

I have a query that 'selects' object of a type: 我有一个查询,“选择”一种类型的对象:

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()

What's happening is that if i set a break-point to the constructor of Foo and step, the constructor is hit and the parameters are loaded with the arguments. 发生的事情是,如果我为Foo和step的构造函数设置一个断点,则构造函数将被命中,并且参数将随参数一起加载。 However, l has empty Foo objects (the members in every object are Nothing ). 但是, l有空的Foo对象(每个对象中的成员均为Nothing )。 What could be happening here? 这里会发生什么?

Change your query to : 将查询更改为:

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()

for more informations you can visit here and here 欲了解更多信息,您可以在这里这里访问

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM