/// <summary> /// Asynchronous. An extension method for the <see cref="IDataRowProvider"/>. Used to perform a lookup with the <see cref="IDataRowProvider"/> interface. If the lookup produces no results, the operation is deemed a failure with the <see cref="DataAccess.EmptyResultSetException"/> Exception. If the operation fails, the incoming Type, and method name will added to Exception. /// </summary> /// <typeparam name="T">The type of object to return.</typeparam> /// <typeparam name="T2">Derived type of T.</typeparam> /// <param name="dataRowProvider">The <see cref="IDataRowProvider"/> used to submit query.</param> /// <param name="dataOrder">The information for the query.</param> /// <param name="converter">A callback used to convert the combination of the <see cref="DataRow"/>, and the <see cref="IAliasedCommandTypeDataOrder"/> into an object of type T.</param> /// <param name="declaringTypeCallback">The callback to define the type to be added to the <see cref="Utilities.OperationResult{T}"/> if faulted.</param> /// <param name="callingMethod">The callback to define the type to be added to the <see cref="Utilities.OperationResult{T}"/> if faulted.</param> /// <returns>A <see cref='Task'/> with a result of <see cref="Utilities.OperationResult{T}"/> containing result upon success, and Exceptions upon failure.</returns> public async static Task <OperationResult <T> > LookupAsync <T, T2>(this IDataRowProvider dataRowProvider, IAliasedCommandTypeDataOrder dataOrder, Func <IAliasedCommandTypeDataOrder, DataRow, T2> converter, Func <Type> declaringTypeCallback, string callingMethod) where T2 : T { OperationResult <List <DataRow> > operation = await dataRowProvider.GetTableAsync(dataOrder, r => r, declaringTypeCallback, callingMethod); return(operation.HadErrors ? new OperationResult <T>(operation.Exceptions) : operation.Result.Any() == false ? new OperationResult <T>(false, default(T)) : new OperationResult <T>(await Task.Run(() => converter(dataOrder, operation.Result[0])))); }
/// <summary> /// Asynchronous. An extension method for the <see cref="IDataRowProvider"/>. Used to produce a list of objects. /// </summary> /// <typeparam name="T">The type of object represented by the lookup.</typeparam> /// <param name="dataRowProvider">The <see cref="IDataRowProvider"/> used to submit query.</param> /// <param name="dataOrder">The information for the query.</param> /// <param name="converter">A callback used to convert the <see cref="DataRow"/>into an object of type T.</param> /// <returns>A <see cref='Task'/> with a result of <see cref="Utilities.OperationResult{T}"/> containing result upon success, and Exceptions upon failure.</returns> public static Task <OperationResult <List <T> > > GetTableAsync <T>(this IDataRowProvider dataRowProvider, IAliasedCommandTypeDataOrder dataOrder, Func <DataRow, T> converter) => dataRowProvider.GetTableAsync(dataOrder, (dO, row) => converter(row));
/// <summary> /// Asynchronous. An extension method for the <see cref="IDataRowProvider"/>. Used to produce a list of objects. If the operation fails, the incoming Type, and method name will added to Exception. /// </summary> /// <typeparam name="T">The type of object represented by the lookup.</typeparam> /// <param name="dataRowProvider">The <see cref="IDataRowProvider"/> used to submit query.</param> /// <param name="dataOrder">The information for the query.</param> /// <param name="converter">A callback used to convert the <see cref="DataRow"/>into an object of type T.</param> /// <param name="declaringTypeCallback">The callback to define the type to be added to the <see cref="Utilities.OperationResult{T}"/> if faulted.</param> /// <param name="callingMethod">The callback to define the type to be added to the <see cref="Utilities.OperationResult{T}"/> if faulted.</param> /// <returns>A <see cref='Task'/> with a result of <see cref="Utilities.OperationResult{T}"/> containing result upon success, and Exceptions upon failure.</returns> public static Task <OperationResult <List <T> > > GetTableAsync <T>(this IDataRowProvider dataRowProvider, IAliasedCommandTypeDataOrder dataOrder, Func <DataRow, T> converter, Func <Type> declaringTypeCallback, string callingMethod) => dataRowProvider.GetTableAsync(dataOrder, (dO, row) => converter(row), declaringTypeCallback, callingMethod);