Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Queryable.AsQueryable(Of TElement) Method (IEnumerable(Of TElement))

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Converts a generic IEnumerable(Of T) to a generic IQueryable(Of T).

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

<ExtensionAttribute>
Public Shared Function AsQueryable(Of TElement) (
	source As IEnumerable(Of TElement)
) As IQueryable(Of TElement)

Parameters

source
Type: System.Collections.Generic.IEnumerable(Of TElement)

A sequence to convert.

Return Value

Type: System.Linq.IQueryable(Of TElement)

An IQueryable(Of T) that represents the input sequence.

Type Parameters

TElement

The type of the elements of source.

Exception Condition
ArgumentNullException

source is null.

If the type of source implements IQueryable(Of T), AsQueryable(Of TElement)(IEnumerable(Of TElement)) returns it directly. Otherwise, it returns an IQueryable(Of T) that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

The following code example demonstrates how to use AsQueryable(Of TElement)(IEnumerable(Of TElement)) to convert an IEnumerable(Of T) to an IQueryable(Of T).

Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

' Convert the List to an IQueryable<int>.
Dim iqueryable As IQueryable(Of Integer) = grades.AsQueryable()

' Get the Expression property of the IQueryable object.
Dim expressionTree As System.Linq.Expressions.Expression = _
    iqueryable.Expression

MsgBox("The NodeType of the expression tree is: " _
    & expressionTree.NodeType.ToString())
MsgBox("The Type of the expression tree is: " _
    & expressionTree.Type.Name)

' This code produces the following output:
'
' The NodeType of the expression tree is: Constant
' The Type of the expression tree is: EnumerableQuery`1

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top
Show:
© 2018 Microsoft