QueryableExtensions.ToListAsync<TSource> Method (IQueryable<TSource>, CancellationToken)
[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]
Creates a List<T> from an IQueryable<T> by enumerating it asynchronously.
Namespace: System.Data.Entity
Assembly: EntityFramework (in EntityFramework.dll)
Syntax
'Declaration
<ExtensionAttribute> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Shared Function ToListAsync(Of TSource) ( _
source As IQueryable(Of TSource), _
cancellationToken As CancellationToken _
) As Task(Of List(Of TSource))
'Usage
Dim source As IQueryable(Of TSource)
Dim cancellationToken As CancellationToken
Dim returnValue As Task(Of List(Of TSource))
returnValue = source.ToListAsync(cancellationToken)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<List<TSource>> ToListAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken cancellationToken
)
[ExtensionAttribute]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TSource>
static Task<List<TSource>^>^ ToListAsync(
IQueryable<TSource>^ source,
CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
static member ToListAsync :
source:IQueryable<'TSource> *
cancellationToken:CancellationToken -> Task<List<'TSource>>
JScript does not support generic types and methods.
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
Type: System.Linq.IQueryable<TSource>
An IQueryable<T> to create a list from.
- cancellationToken
Type: System.Threading.CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks.Task<List<TSource>>
A task that represents the asynchronous operation. The task result contains a List<T> that contains elements from the input sequence.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IQueryable<TSource>. When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.113) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.113).
Remarks
Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.