DbRawSqlQuery<TElement>.SingleOrDefaultAsync Method (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 returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

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

Syntax

'Declaration
Public Function SingleOrDefaultAsync ( _
    cancellationToken As CancellationToken _
) As Task(Of TElement)
'Usage
Dim instance As DbRawSqlQuery 
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of TElement)

returnValue = instance.SingleOrDefaultAsync(cancellationToken)
public Task<TElement> SingleOrDefaultAsync(
    CancellationToken cancellationToken
)
public:
Task<TElement>^ SingleOrDefaultAsync(
    CancellationToken cancellationToken
)
member SingleOrDefaultAsync : 
        cancellationToken:CancellationToken -> Task<'TElement> 
public function SingleOrDefaultAsync(
    cancellationToken : CancellationToken
) : Task<TElement>

Parameters

Return Value

Type: System.Threading.Tasks.Task<TElement>
A task that represents the asynchronous operation. The task result contains the single element of the query result, or default ( TElement ) if the sequence contains no elements.

Exceptions

Exception Condition
InvalidOperationException

The query result has more than one element.

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

DbRawSqlQuery<TElement> Class

SingleOrDefaultAsync Overload

System.Data.Entity.Infrastructure Namespace