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

Definizione

Overload

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

Converte un' IEnumerable a un IQueryable.Converts an IEnumerable to an IQueryable.

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

Converte un oggetto generico IEnumerable<T> generico IQueryable<T>.Converts a generic IEnumerable<T> to a generic IQueryable<T>.

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

Converte un' IEnumerable a un IQueryable.Converts 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

Parametri

source
IEnumerable IEnumerable IEnumerable IEnumerable

Sequenza da convertire.A sequence to convert.

Restituisce

Un IQueryable che rappresenta la sequenza di input.An IQueryable that represents the input sequence.

Eccezioni

source non implementa IEnumerable<T> per alcuni T.source does not implement IEnumerable<T> for some T.

Commenti

Se il tipo della source implementi IQueryable<T>, AsQueryable(IEnumerable) restituisce direttamente.If the type of source implements IQueryable<T>, AsQueryable(IEnumerable) returns it directly. In caso contrario, restituisce un IQueryable<T> che esegue query chiamando metodi degli operatori di query equivalente Enumerable invece di quelle nello Queryable.Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

Questo metodo presuppone che source implementi IEnumerable<T> per alcuni T.This method assumes that source implements IEnumerable<T> for some T. In fase di esecuzione, il risultato è di tipo IQueryable<T> per lo stesso T.At runtime, the result is of type IQueryable<T> for the same T. Questo metodo è utile negli scenari dinamici quando non si conosce il tipo di staticamente 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>)

Converte un oggetto generico IEnumerable<T> generico 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)

Parametri di tipo

TElement

Tipo degli elementi di source.The type of the elements of source.

Parametri

source
IEnumerable<TElement>

Sequenza da convertire.A sequence to convert.

Restituisce

IQueryable<TElement>

Un IQueryable<T> che rappresenta la sequenza di input.An IQueryable<T> that represents the input sequence.

Eccezioni

Esempi

Esempio di codice seguente viene illustrato come utilizzare AsQueryable<TElement>(IEnumerable<TElement>) per convertire un' IEnumerable<T> a un 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

Commenti

Se il tipo della source implementi IQueryable<T>, AsQueryable<TElement>(IEnumerable<TElement>) restituisce direttamente.If the type of source implements IQueryable<T>, AsQueryable<TElement>(IEnumerable<TElement>) returns it directly. In caso contrario, restituisce un IQueryable<T> che esegue query chiamando metodi degli operatori di query equivalente Enumerable invece di quelle nello Queryable.Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

Si applica a