简体   繁体   中英

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. However, l has empty Foo objects (the members in every object are 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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