Queryable.AsQueryable Queryable.AsQueryable Queryable.AsQueryable Queryable.AsQueryable Method

定义

重载

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>)

将泛型 IEnumerable<T> 转换为泛型 IQueryable<T>Converts a generic IEnumerable<T> to a generic IQueryable<T>.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable ^ AsQueryable(System::Collections::IEnumerable ^ source);
public static System.Linq.IQueryable AsQueryable (this System.Collections.IEnumerable source);
static member AsQueryable : System.Collections.IEnumerable -> System.Linq.IQueryable
<Extension()>
Public Function AsQueryable (source As IEnumerable) As IQueryable

参数

source
IEnumerable IEnumerable IEnumerable IEnumerable

要转换的序列。A sequence to convert.

返回

一个 IQueryable,表示输入序列。An IQueryable that represents the input sequence.

异常

source 未为某些 T 实现 IEnumerable<T>source does not implement IEnumerable<T> for some T.

注解

如果source AsQueryable(IEnumerable)实现IQueryable<T>的类型, 则直接返回该类型。If the type of source implements IQueryable<T>, AsQueryable(IEnumerable) returns it directly. 否则, 它将返回IQueryable<T> , 通过调用中Enumerable的等效查询运算符方法 (而不是中Queryable的) 来执行查询。Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

此方法假定source为某些IEnumerable<T> T实现。This method assumes that source implements IEnumerable<T> for some T. 在运行时, 结果的类型IQueryable<T>为相同T的。At runtime, the result is of type IQueryable<T> for the same T. 当您静态知道的类型T时, 此方法在动态情况下非常有用。This method is useful in dynamic scenarios when you do not statically know the type of T.

AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>) AsQueryable<TElement>(IEnumerable<TElement>)

将泛型 IEnumerable<T> 转换为泛型 IQueryable<T>Converts a generic IEnumerable<T> to a generic IQueryable<T>.

public:
generic <typename TElement>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::IQueryable<TElement> ^ AsQueryable(System::Collections::Generic::IEnumerable<TElement> ^ source);
public static System.Linq.IQueryable<TElement> AsQueryable<TElement> (this System.Collections.Generic.IEnumerable<TElement> source);
static member AsQueryable : seq<'Element> -> System.Linq.IQueryable<'Element>
<Extension()>
Public Function AsQueryable(Of TElement) (source As IEnumerable(Of TElement)) As IQueryable(Of TElement)

类型参数

TElement

source 的元素类型。The type of the elements of source.

参数

source
IEnumerable<TElement>

要转换的序列。A sequence to convert.

返回

IQueryable<TElement>

一个 IQueryable<T>,表示输入序列。An IQueryable<T> that represents the input sequence.

异常

示例

下面的代码示例演示如何使用AsQueryable<TElement>(IEnumerable<TElement>) IEnumerable<T>将转换为IQueryable<T>The following code example demonstrates how to use AsQueryable<TElement>(IEnumerable<TElement>) to convert an IEnumerable<T> to an IQueryable<T>.

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
*/
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

注解

如果source AsQueryable<TElement>(IEnumerable<TElement>)实现IQueryable<T>的类型, 则直接返回该类型。If the type of source implements IQueryable<T>, AsQueryable<TElement>(IEnumerable<TElement>) returns it directly. 否则, 它将返回IQueryable<T> , 通过调用中Enumerable的等效查询运算符方法 (而不是中Queryable的) 来执行查询。Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

适用于