DevForce Help Reference
SingleOrDefault<TSource>(IEntityScalarQuery<TSource>,Expression<Func<TSource,Boolean>>) Method
Example 


Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Function SingleOrDefault(Of TSource)( _
   ByVal source As IEntityScalarQuery(Of TSource), _
   ByVal predicate As Expression(Of Func(Of TSource,Boolean)) _
) As Task(Of TSource)
'Usage
 
Dim source As IEntityScalarQuery(Of TSource)
Dim predicate As Expression(Of Func(Of TSource,Boolean))
Dim value As Task(Of TSource)
 
value = EntityScalarAsyncExtensions.SingleOrDefault(Of TSource)(source, predicate)

Parameters

source
predicate

Type Parameters

TSource
Example
public async void AsyncSingleOrDefaultWithPredicate() {
   Employee emp = await _entityManager.Employees.AsScalarAsync().SingleOrDefault(e => e.Id == 1);
 }
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityScalarAsyncExtensions Class
EntityScalarAsyncExtensions Members
Overload List

Send Feedback