/// <summary> /// Asynchronously loads first record from query. /// Throws exception, if query doesn't return exactly one record. /// </summary> /// <typeparam name="TSource">Query element type.</typeparam> /// <param name="source">Source query.</param> /// <param name="token">Optional asynchronous operation cancellation token.</param> /// <returns>First record from query results.</returns> public static Task <TSource> SingleAsyncLinqToDB <TSource>( this IQueryable <TSource> source, CancellationToken token = default) => AsyncExtensions.SingleAsync(source.ToLinqToDB(), token);
/// <summary> /// Asynchronously loads first record from query, filtered using provided predicate. /// Throws exception, if query doesn't return exactly one record. /// </summary> /// <typeparam name="TSource">Query element type.</typeparam> /// <param name="source">Source query.</param> /// <param name="predicate">Query filter predicate.</param> /// <param name="token">Optional asynchronous operation cancellation token.</param> /// <returns>First record from query results.</returns> public static Task <TSource> SingleAsyncLinqToDB <TSource>( this IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate, CancellationToken token = default) => AsyncExtensions.SingleAsync(source.ToLinqToDB(), predicate, token);
/// <summary> /// Returns the only element of a sequence that satisfies a specified condition, /// and throws an exception if more than one such element exists /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="source">An sequence to return a single element from</param> /// <param name="predicate">A function to test an element for a condition</param> /// <returns>The single element of the input sequence that satisfies the condition in predicate</returns> public static Task <TSource> SingleAsync <TSource>(this IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate = null) { return(predicate == null?AsyncExtensions.SingleAsync(source) : AsyncExtensions.SingleAsync(source, predicate)); }