Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

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)
Dim source As IEnumerable(Of TElement)
Dim returnValue As IQueryable(Of TElement)

returnValue = source.AsQueryable()

Type Parameters


The type of the elements of 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.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(Of TElement). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).


source is Nothing.

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 = _

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

Community Additions

© 2015 Microsoft