QueryableExtensions.ContainsAsync<TSource> Method (IQueryable<TSource>, 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.]

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

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function ContainsAsync(Of TSource) ( _
    source As IQueryable(Of TSource), _
    item As TSource, _
    cancellationToken As CancellationToken _
) As Task(Of Boolean)
'Usage
Dim source As IQueryable(Of TSource)
Dim item As TSource
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of Boolean)

returnValue = source.ContainsAsync(item, _
    cancellationToken)
public static Task<bool> ContainsAsync<TSource>(
    this IQueryable<TSource> source,
    TSource item,
    CancellationToken cancellationToken
)
[ExtensionAttribute]
public:
generic<typename TSource>
static Task<bool>^ ContainsAsync(
    IQueryable<TSource>^ source, 
    TSource item, 
    CancellationToken cancellationToken
)
static member ContainsAsync : 
        source:IQueryable<'TSource> * 
        item:'TSource * 
        cancellationToken:CancellationToken -> Task<bool> 
JScript does not support generic types and methods.

Type Parameters

  • TSource
    The type of the elements of source.

Parameters

  • item
    Type: TSource
    The object to locate in the sequence.

Return Value

Type: System.Threading.Tasks.Task<Boolean>
A task that represents the asynchronous operation. The task result contains true if the input sequence contains the specified value; otherwise, false.

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).

Exceptions

Exception Condition
ArgumentNullException

source is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider .

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 Also

Reference

QueryableExtensions Class

ContainsAsync Overload

System.Data.Entity Namespace