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

定義

多載

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

將轉換IEnumerableIQueryableConverts 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)

將轉換IEnumerableIQueryableConverts 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 不會實作IEnumerable<T>某些Tsource does not implement IEnumerable<T> for some T.

備註

如果類型source會實作IQueryable<T>AsQueryable(IEnumerable)會直接傳回。If the type of source implements IQueryable<T>, AsQueryable(IEnumerable) returns it directly. 否則,它會傳回IQueryable<T>藉由呼叫的對等查詢運算子方法,在執行查詢Enumerable而不是在QueryableOtherwise, 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>某些TThis method assumes that source implements IEnumerable<T> for some T. 在執行階段,則結果會是型別IQueryable<T>而言,同一個TAt runtime, the result is of type IQueryable<T> for the same T. 此方法相當實用動態案例中,當您無法以靜態方式知道的型別TThis 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會實作IQueryable<T>AsQueryable<TElement>(IEnumerable<TElement>)會直接傳回。If the type of source implements IQueryable<T>, AsQueryable<TElement>(IEnumerable<TElement>) returns it directly. 否則,它會傳回IQueryable<T>藉由呼叫的對等查詢運算子方法,在執行查詢Enumerable而不是在QueryableOtherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

適用於