Skip to main content
.NET Framework Class Library
QueryableAsQueryableTElement Method (IEnumerableTElement)

Converts a generic IEnumerableT to a generic IQueryableT.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)
Syntax
<[%$TOPIC/bb507003_en-us_VS_110_3_0_0_0_0%]> _
Public Shared Function AsQueryable(Of TElement) ( _
	source As [%$TOPIC/bb507003_en-us_VS_110_3_0_0_0_1%](Of TElement) _
) As [%$TOPIC/bb507003_en-us_VS_110_3_0_0_0_2%](Of TElement)
public static [%$TOPIC/bb507003_en-us_VS_110_3_0_1_0_0%]<TElement> AsQueryable<TElement>(
	this [%$TOPIC/bb507003_en-us_VS_110_3_0_1_0_1%]<TElement> source
)
[[%$TOPIC/bb507003_en-us_VS_110_3_0_2_0_0%]]
public:
generic<typename TElement>
static [%$TOPIC/bb507003_en-us_VS_110_3_0_2_0_1%]<TElement>^ AsQueryable(
	[%$TOPIC/bb507003_en-us_VS_110_3_0_2_0_2%]<TElement>^ source
)
static member AsQueryable : 
        source:[%$TOPIC/bb507003_en-us_VS_110_3_0_3_0_0%]<'TElement> -> [%$TOPIC/bb507003_en-us_VS_110_3_0_3_0_1%]<'TElement> 

Type Parameters

TElement

The type of the elements of source.

Parameters

source
Type: System.Collections.GenericIEnumerableTElement

A sequence to convert.

Return Value

Type: System.LinqIQueryableTElement
An IQueryableT 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 IEnumerableTElement. 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).
Exceptions
ExceptionCondition
ArgumentNullException

source is .

Remarks

If the type of source implements IQueryableT, AsQueryableTElement(IEnumerableTElement) returns it directly. Otherwise, it returns an IQueryableT that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

Examples

The following code example demonstrates how to use AsQueryableTElement(IEnumerableTElement) to convert an IEnumerableT to an IQueryableT.

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
List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

// Convert the List to an IQueryable<int>.
IQueryable<int> iqueryable = grades.AsQueryable();

// Get the Expression property of the IQueryable object.
System.Linq.Expressions.Expression expressionTree =
    iqueryable.Expression;

Console.WriteLine("The NodeType of the expression tree is: "
    + expressionTree.NodeType.ToString());
Console.WriteLine("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
*/
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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