【问题标题】:Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' 类型的表达式不可查询
【发布时间】:2019-03-19 14:26:48
【问题描述】:

我的班级给了我一个错误:

Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.

我搜索了类似的问题,发现导入/引用可能有问题。但是,我想我导入了我需要的所有东西,但它仍然给了我错误。

类和项目参考如下:

Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq


Public Class Form1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Dim Result As Integer
    Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")


    Private Function GetProcedureName(ByVal Name As String) As String
        Dim Result As String = String.Empty
        'this line gives the error
        Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.@name = Name
        For Each Elem As XElement In Elems
            Result = Elem...<target>...<remote>...<source>.@name
            Exit For
        Next
        Return Result
    End Function


End Class

【问题讨论】:

    标签: vb.net .net-3.5 smart-device


    【解决方案1】:

    您没有 System.Linq 的导入,这意味着编译器找不到 LINQ to Objects,这是您尝试使用的 LINQ 实现。

    只需将其添加到您的导入中:

    Imports System.Linq
    

    LINQ to XML 并不是真正的 LINQ 提供程序 - 它只是一个 XML API,它也可以很好地与 LINQ to Objects 配合使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      相关资源
      最近更新 更多