Exemplo n.º 1
0
 public static T ToObject<T>(this DbDataReader reader, string readerName, string[] excludeFields, ObjectsChangeTracker changeTracker)
 {
     T result = new DataReaderToObjectMapper<T>(readerName, null, excludeFields).MapUsingState(reader, reader);
     if (changeTracker != null)
     {
         changeTracker.RegisterObject(result);
     }
     return result;
 }
Exemplo n.º 2
0
        /// <summary>
        /// To the objects.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reader">The reader.</param>
        /// <param name="readerName">Name of the reader.</param>
        /// <param name="excludeFields">The exclude fields.</param>
        /// <param name="changeTracker">The change tracker.</param>
        /// <returns>IEnumerable{``0}.</returns>
        public static IEnumerable <T> ToObjects <T>(this IDataReader reader, string readerName, string[] excludeFields, ObjectsChangeTracker changeTracker)
        {
            if (string.IsNullOrEmpty(readerName))
            {
                var mappingKeyBuilder = new StringBuilder();
                for (int i = 0; i < reader.FieldCount; ++i)
                {
                    mappingKeyBuilder.Append(reader.GetName(i));
                    mappingKeyBuilder.Append(' ');
                }
                readerName = mappingKeyBuilder.ToString();
            }

            var mapper = new DataReaderToObjectMapper <T>(readerName, null, excludeFields);

            while (reader.Read())
            {
                yield return(mapper.ReadSingle(reader, changeTracker));
            }
        }