类型'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)'的表达式不可查询

时间:2018-10-15 07:47:19

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

我的课给我一个错误:

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.

我搜索了类似的问题,发现可能是导入/引用存在问题。但是,我认为我导入了我需要的所有内容,但仍然给我错误。

类和项目参考如下:

references

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

1 个答案:

答案 0 :(得分:4)

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

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

Imports System.Linq

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