1

我正面临一个 LINQ 的技巧问题。我生成上面的代码:

... '返回一个对象

Dim lReturn = (From tb_hb In lObjLNQContext.tb_hbs _
    Where tb_hb.id_process = codigoProcessamento _
    Order By tb_hb.dth_hb Ascending _
    Select tb_hb.id_process, tb_hb.dth_hb).AsEnumerable

Return lReturn

当我检查 lReturn DataType 是 Linq.DataQuery 时。

我使用上面的代码来访问数据:

For Each row In lResult
  Console.WriteLine(row.dth_hb)

如果我关闭 Option Explicit,一切都运行良好。当我打开它时,编译器向我显示一条消息:表达式是“对象”类型,它不是集合类型。引用 lResult 变量。

我真的不知道如何解决它。

谢谢你的帮助。

4

1 回答 1

2

Your LINQ expression uses anonymous types, which are only available in one method.

Define a class to hold the two values id_process, dth_hb and change your select to create instances of the class. Then you can declare the function as returning List Of the new class

Example here

于 2012-05-26T06:24:43.393 回答