Пример #1
0
        public T Convert(DbDataReader reader)
        {
            if (_mappings == null || reader != _lastReader)
            {
                _mappings = MapProperties(reader);
            }

            var o = new T();

            foreach (var mapping in _mappings)
            {
                var prop     = mapping.Property;
                var rawValue = reader.GetValue(mapping.Index);
                var value    = DbConvert.To(prop.PropertyType, rawValue);
                prop.SetValue(o, value, null);
            }

            _lastReader = reader;

            return(o);
        }
Пример #2
0
 public static T Get <T>(this DbDataReader reader, string name)
 {
     return(DbConvert.To <T>(reader[name], CultureInfo.CurrentCulture));
 }
Пример #3
0
 public static T Get <T>(this DbDataReader reader, string name, IFormatProvider provider)
 {
     return(DbConvert.To <T>(reader[name], provider));
 }
Пример #4
0
 public static T Get <T>(this DbDataReader reader, int ordinal)
 {
     return(DbConvert.To <T>(reader[ordinal], CultureInfo.CurrentCulture));
 }
Пример #5
0
 public static T Get <T>(this DbDataReader reader, int ordinal, IFormatProvider provider)
 {
     return(DbConvert.To <T>(reader[ordinal], provider));
 }