Exemple #1
0
 public ResultSetEnumerator(IDataResultsBase results, IDataReaderAsync reader, IExecutionContext context, Func <IDataRecord, T> read, int set)
 {
     _results = results;
     _reader  = reader;
     _context = context;
     _read    = read;
     _set     = set;
 }
Exemple #2
0
        /// <summary>
        /// Iterate through all remaining rows in the next N result sets, mapping all rows to objects
        /// of the given type. Useful only if the next N result sets all represent the same type
        /// of object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="results"></param>
        /// <param name="numResultSets">The number of result sets to consume</param>
        /// <param name="setup"></param>
        /// <returns></returns>
        public static IEnumerable <T> AsEnumerableNextSeveral <T>(this IDataResultsBase results, int numResultSets, Action <IMapCompilerSettings> setup = null)
        {
            Argument.NotNull(results, nameof(results));
            if (numResultSets <= 0)
            {
                yield break;
            }

            var values     = results.AsEnumerable <T>(setup);
            var currentSet = results.CurrentSet;

            foreach (var value in values)
            {
                if (currentSet != results.CurrentSet)
                {
                    throw DataReaderException.EnumeratorBroken();
                }
                yield return(value);
            }
            numResultSets--;

            while (numResultSets > 0)
            {
                // Make sure we're still where we think we are
                if (currentSet != results.CurrentSet)
                {
                    throw DataReaderException.EnumeratorBroken();
                }

                // Move to the next result set
                var hasMore = results.TryAdvanceToNextResultSet();
                if (!hasMore)
                {
                    yield break;
                }
                numResultSets--;

                // Make sure the next set is what we expect (no preemption)
                var nextSet = results.CurrentSet;
                if (nextSet != currentSet + 1)
                {
                    throw DataReaderException.EnumeratorBroken();
                }
                currentSet = nextSet;

                // Enumerate, checking before each value to make sure we are still on the correct
                // result set
                var nextValues = results.AsEnumerable <T>(setup);
                foreach (var value in nextValues)
                {
                    if (currentSet != results.CurrentSet)
                    {
                        throw DataReaderException.EnumeratorBroken();
                    }
                    yield return(value);
                }
            }
        }
Exemple #3
0
 public DataRecordMappingEnumerable(IDataResultsBase results, IDataReaderAsync reader, IExecutionContext context, Func <IDataRecord, T> map)
 {
     Argument.NotNull(reader, nameof(reader));
     Argument.NotNull(context, nameof(context));
     Argument.NotNull(map, nameof(map));
     _results      = results;
     _reader       = reader;
     _context      = context;
     _map          = map;
     _currentSet   = results.CurrentSet;
     _readAttempts = 0;
 }
Exemple #4
0
 /// <summary>
 /// Get all output parameters as a single object, with each parameter being mapped to a
 /// property with the same name (case invariant). Parameters will be mapped to property
 /// types where possible. Otherwise default values will be assigned.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="results"></param>
 /// <returns></returns>
 public static T GetOutputParameters <T>(this IDataResultsBase results)
     where T : class, new()
 {
     Argument.NotNull(results, nameof(results));
     return(results.GetParameters().GetOutputParameters <T>());
 }
Exemple #5
0
 /// <summary>
 /// Get the value of the output parameter with the given name, attempting to convert it
 /// to the specified type if possible. If conversion is not possible, an exception will
 /// be thrown.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="results"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static T GetOutputParameterOrThrow <T>(this IDataResultsBase results, string name)
 {
     Argument.NotNull(results, nameof(results));
     return(results.GetParameters().GetOutputParameterOrThrow <T>(name));
 }
Exemple #6
0
 /// <summary>
 /// Get the value of the output parameter with the given name
 /// </summary>
 /// <param name="results"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static object GetOutputParameterValue(this IDataResultsBase results, string name)
 {
     Argument.NotNull(results, nameof(results));
     return(results.GetParameters().GetValue(name));
 }
Exemple #7
0
 /// <summary>
 /// Try to advance to the next result set, returning false if the exception fails
 /// </summary>
 /// <param name="results"></param>
 /// <returns></returns>
 public static bool TryAdvanceToNextResultSet(this IDataResultsBase results)
 {
     Argument.NotNull(results, nameof(results));
     return(results.TryAdvanceToResultSet(results.CurrentSet + 1));
 }
Exemple #8
0
 /// <summary>
 /// Iterate through all remaining rows in all remaining result sets and map them all to
 /// objects of the same type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="results"></param>
 /// <param name="setup"></param>
 /// <returns></returns>
 public static IEnumerable <T> AsEnumerableAll <T>(this IDataResultsBase results, Action <IMapCompilerSettings> setup = null)
 {
     return(AsEnumerableNextSeveral <T>(results, int.MaxValue, setup));
 }
Exemple #9
0
 /// <summary>
 /// Advance to the next result set and map it to an enumerable of objects using the given mapping
 /// compiler and options.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="results"></param>
 /// <param name="setup"></param>
 /// <returns></returns>
 public static IEnumerable <T> GetNextEnumerable <T>(this IDataResultsBase results, Action <IMapCompilerSettings> setup = null)
 {
     Argument.NotNull(results, nameof(results));
     return(results.AdvanceToNextResultSet().AsEnumerable <T>(setup));
 }