Delen via


EntityFrameworkQueryableExtensions.ContainsAsync<TSource> Method

Definition

Asynchronously determines whether a sequence contains a specified element by using the default equality comparer.

public static System.Threading.Tasks.Task<bool> ContainsAsync<TSource> (this System.Linq.IQueryable<TSource> source, TSource item, System.Threading.CancellationToken cancellationToken = default);
static member ContainsAsync : System.Linq.IQueryable<'Source> * 'Source * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
<Extension()>
Public Function ContainsAsync(Of TSource) (source As IQueryable(Of TSource), item As TSource, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Boolean)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IQueryable<T> to return the single element of.

item
TSource

The object to locate in the sequence.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

A task that represents the asynchronous operation. The task result contains true if the input sequence contains the specified value; otherwise, false.

Exceptions

source is null.

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. See Avoiding DbContext threading issues for more information and examples.

See Querying data with EF Core for more information and examples.

Applies to