LINQ to DataSet,DataTable.AsEnumerable() 无法识别

LINQ to DataSet, DataTable.AsEnumerable() not recognized(LINQ to DataSet,DataTable.AsEnumerable() 无法识别)
本文介绍了LINQ to DataSet,DataTable.AsEnumerable() 无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 LINQ 的新手,正在尝试用它查询我的 DataSet.所以我跟着 this example 到了这封信,但它不起作用.

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

我的项目中的引用是:

System
System.Data
System.Drawing
System.Windows.Forms
System.Xml

推荐答案

虽然包含扩展的类位于 System.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() 无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)