Converts a generic IEnumerable
Assembly: System.Core (in System.Core.dll)
<ExtensionAttribute> _
Public Shared Function AsQueryable(Of TElement) ( _
source As IEnumerable(Of TElement) _
) As IQueryable(Of TElement)public static IQueryable<TElement> AsQueryable<TElement>(
this IEnumerable<TElement> source
)
[ExtensionAttribute]
public:
generic<typename TElement>
static IQueryable<TElement>^ AsQueryable(
IEnumerable<TElement>^ source
)static member AsQueryable :
source:IEnumerable<'TElement> -> IQueryable<'TElement>
Type Parameters
- TElement
The type of the elements of source.
Parameters
- source
- Type: System.Collections.Generic
. . :: . IEnumerable< (Of < ( TElement> ) > )
A sequence to convert.
Return Value
Type: System.LinqAn IQueryable
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable| Exception | Condition |
|---|---|
| ArgumentNullException | source is |
If the type of source implements IQueryable
The following code example demonstrates how to use AsQueryable
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
*/
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.