Queryable.AsQueryable Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Перегрузки
| Имя | Описание |
|---|---|
| AsQueryable(IEnumerable) |
Преобразует IEnumerable в IQueryable. |
| AsQueryable<TElement>(IEnumerable<TElement>) |
Преобразует универсальный IEnumerable<T> в универсальный IQueryable<T>. |
AsQueryable(IEnumerable)
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
Преобразует IEnumerable в 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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
public static System.Linq.IQueryable AsQueryable(this System.Collections.IEnumerable source);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
public static System.Linq.IQueryable AsQueryable(this System.Collections.IEnumerable source);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IQueryable AsQueryable(this System.Collections.IEnumerable source);
static member AsQueryable : System.Collections.IEnumerable -> System.Linq.IQueryable
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
static member AsQueryable : System.Collections.IEnumerable -> System.Linq.IQueryable
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
static member AsQueryable : System.Collections.IEnumerable -> System.Linq.IQueryable
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
static member AsQueryable : System.Collections.IEnumerable -> System.Linq.IQueryable
<Extension()>
Public Function AsQueryable (source As IEnumerable) As IQueryable
Параметры
- source
- IEnumerable
Последовательность для преобразования.
Возвращаемое значение
Объект, IQueryable представляющий входную последовательность.
- Атрибуты
Исключения
source не реализуется IEnumerable<T> для некоторых T.
source равно null.
Комментарии
Если тип source реализации IQueryable<T>, AsQueryable(IEnumerable) возвращает его напрямую. В противном случае он возвращает IQueryable<T> запросы, вызывая эквивалентные методы оператора запросов вместо Enumerable тех, в которых они выполняются Queryable.
Этот метод предполагает, что source реализуется для некоторых IEnumerable<T>T. В среде выполнения результат имеет тип IQueryable<T> для одного и того же T. Этот метод полезен в динамических сценариях, если вы не статически знаете тип T.
Применяется к
AsQueryable<TElement>(IEnumerable<TElement>)
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
- Исходный код:
- Queryable.cs
Преобразует универсальный IEnumerable<T> в универсальный 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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
public static System.Linq.IQueryable<TElement> AsQueryable<TElement>(this System.Collections.Generic.IEnumerable<TElement> source);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
public static System.Linq.IQueryable<TElement> AsQueryable<TElement>(this System.Collections.Generic.IEnumerable<TElement> source);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IQueryable<TElement> AsQueryable<TElement>(this System.Collections.Generic.IEnumerable<TElement> source);
static member AsQueryable : seq<'Element> -> System.Linq.IQueryable<'Element>
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating in-memory collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
static member AsQueryable : seq<'Element> -> System.Linq.IQueryable<'Element>
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
static member AsQueryable : seq<'Element> -> System.Linq.IQueryable<'Element>
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Enumerating in-memory collections as IQueryable can require unreferenced code because expressions referencing IQueryable extension methods can get rebound to IEnumerable extension methods. The IEnumerable extension methods could be trimmed causing the application to fail at runtime.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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.
Параметры
- source
- IEnumerable<TElement>
Последовательность для преобразования.
Возвращаемое значение
Объект, IQueryable<T> представляющий входную последовательность.
- Атрибуты
Исключения
source равно null.
Примеры
В следующем примере кода показано, как использовать AsQueryable<TElement>(IEnumerable<TElement>) для преобразования объекта IEnumerable<T> в объект 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>) возвращает его напрямую. В противном случае он возвращает IQueryable<T> запросы, вызывая эквивалентные методы оператора запросов вместо Enumerable тех, в которых они выполняются Queryable.