LINQ to DataSet,DataTable.AsEnumerable()无法识别 [英] LINQ to DataSet, DataTable.AsEnumerable() not recognized
问题描述
我是全新的 LINQ
,我试图用它查询我的 DataSet
。所以我遵循了这个例子给这封信,它不起作用。
I am brand new to LINQ
and am trying to query my DataSet
with it. So I followed this example to the letter, and it does not work.
我知道我的 DataTable
需要 .AsEnumerable
最终,但它不被 IDE识别
。我究竟做错了什么?我错过了示例中未显示的引用/引用(不会是第一次MSDN示例不正确),如果是这样,哪一个?还是还有别的东西?
I know that my DataTable
needs the .AsEnumerable
on the end, but it is not recognized by the IDE
. What am I doing wrong? Am I missing a reference/import that is not shown in the example (wouldn't be the first time a MSDN example was not quite right), and if so, which one? Or is it something else altogether?
示例代码
Imports System
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Globalization
//Fill the DataSet.
Dim ds As New DataSet()
ds.Locale = CultureInfo.InvariantCulture
//See the FillDataSet method in the Loading Data Into a DataSet topic.
FillDataSet(ds)
Dim products As DataTable = ds.Tables("Product")
Dim query = From product In products.AsEnumerable() _
Select product
Console.WriteLine("Product Names:")
For Each p In query
Console.WriteLine(p.Field(Of String)("Name"))
Next
我的项目中的参考文献是:
The References in my project are:
System
System.Data
System.Drawing
System.Windows.Forms
System.Xml
推荐答案
持有扩展名的类位于系统.Data
命名空间,它位于默认情况下不会添加到项目的程序集中。添加对 System.Data.DataSetExtensions
的引用到您的项目,它应该是可以的。记住,即使在添加了引用之后,任何期望使用类中定义的扩展方法的类也需要为System.Data使用一个using语句。
While the class holding the extensions is in the System.Data
namespace, it's located in an assembly that isn't added to your project by default. Add a reference to System.Data.DataSetExtensions
to your project and it should be ok. Remember that, even after you've added the reference, any class that expects to use the extension methods defined in the class will need to have a using statement for System.Data as well.
这篇关于LINQ to DataSet,DataTable.AsEnumerable()无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!