QueryableExtensions::FirstAsync Method
Asynchronously returns the first element of a sequence.
Assembly: EntityFramework (in EntityFramework.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | FirstAsync<TSource>(IQueryable<TSource>^) | Asynchronously returns the first element of a sequence. |
![]() ![]() | FirstAsync<TSource>(IQueryable<TSource>^, CancellationToken) | Asynchronously returns the first element of a sequence. |
![]() ![]() | FirstAsync<TSource>(IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^) | Asynchronously returns the first element of a sequence that satisfies a specified condition. |
![]() ![]() | FirstAsync<TSource>(IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^, CancellationToken) | Asynchronously returns the first element of a sequence that satisfies a specified condition. |
QueryableExtensions::FirstAsync<TSource> Method (IQueryable<TSource>^)
Asynchronously returns the first element of a sequence.
public: generic<typename TSource> [ExtensionAttribute] static Task<TSource>^ FirstAsync( IQueryable<TSource>^ source )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the first element of.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the first element in source.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source is null. |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider. |
| InvalidOperationException | The source sequence is empty. |
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.
QueryableExtensions::FirstAsync<TSource> Method (IQueryable<TSource>^, CancellationToken)
Asynchronously returns the first element of a sequence.
public: generic<typename TSource> [ExtensionAttribute] static Task<TSource>^ FirstAsync( IQueryable<TSource>^ source, CancellationToken cancellationToken )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the first element of.
- cancellationToken
-
Type:
System.Threading::CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the first element in source.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | The source sequence is empty. |
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.
QueryableExtensions::FirstAsync<TSource> Method (IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^)
Asynchronously returns the first element of a sequence that satisfies a specified condition.
public: generic<typename TSource> [SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [ExtensionAttribute] static Task<TSource>^ FirstAsync( IQueryable<TSource>^ source, Expression<Func<TSource, bool>^>^ predicate )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the first element of.
- predicate
-
Type:
System.Linq.Expressions::Expression<Func<TSource, Boolean>^>^
A function to test each element for a condition.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the first element in source that passes the test in predicate.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source or predicate is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | No element satisfies the condition in predicate . |
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.
QueryableExtensions::FirstAsync<TSource> Method (IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^, CancellationToken)
Asynchronously returns the first element of a sequence that satisfies a specified condition.
public: generic<typename TSource> [SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [ExtensionAttribute] static Task<TSource>^ FirstAsync( IQueryable<TSource>^ source, Expression<Func<TSource, bool>^>^ predicate, CancellationToken cancellationToken )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the first element of.
- predicate
-
Type:
System.Linq.Expressions::Expression<Func<TSource, Boolean>^>^
A function to test each element for a condition.
- cancellationToken
-
Type:
System.Threading::CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the first element in source that passes the test in predicate.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source or predicate is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | No element satisfies the condition in predicate . |
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.

