/// <summary> /// Asynchronously loads first record from query. /// Returns <c>default(TSource)</c>, if query doesn't return any records. /// </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 or <c>default(TSource)</c> for empty resultset.</returns> public static Task <TSource> FirstOrDefaultAsyncLinqToDB <TSource>( this IQueryable <TSource> source, CancellationToken token = default) => AsyncExtensions.FirstOrDefaultAsync(source.ToLinqToDB(), token);
/// <summary> /// Asynchronously loads first record from query, filtered using provided predicate. /// Returns <c>default(TSource)</c>, if query doesn't return any records. /// </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 or <c>default(TSource)</c> for empty resultset.</returns> public static Task <TSource> FirstOrDefaultAsyncLinqToDB <TSource>( this IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate, CancellationToken token = default) => AsyncExtensions.FirstOrDefaultAsync(source.ToLinqToDB(), predicate, token);
/// <summary> /// Returns the first element of a sequence, or a default value if the sequence contains no elements /// </summary> /// <typeparam name="TSource">The type of the elements of source</typeparam> /// <param name="source">Source</param> /// <param name="predicate">Predicate</param> /// <returns>default(TSource) if source is empty; otherwise, the first element in source</returns> public static Task <TSource> FirstOrDefaultAsync <TSource>(this IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate = null) { return(predicate == null?AsyncExtensions.FirstOrDefaultAsync(source) : AsyncExtensions.FirstOrDefaultAsync(source, predicate)); }