public IList <T> GetValues <T>(Command cmd, Region region) { TimeWatch.Start("Peanut->Execute SQL Return Values"); List <T> result = null; object value; if (region == null) { region = new Region(0, 9999999); } if (region.Size > DBContext.DefaultListMaxSize) { result = new List <T>(DBContext.DefaultListMaxSize); } else { result = new List <T>(region.Size); } using (IDataReader reader = ExecuteReader(cmd)) { int index = 0; while (reader.Read()) { if (index >= region.Start) { value = reader[0]; if (value != DBNull.Value) { result.Add((T)Uility.ChangeType(value, typeof(T))); } else { result.Add(default(T)); } if (result.Count == region.Size) { cmd.DbCommand.Cancel(); reader.Close(); break; } } index++; } } TimeWatch.End(); return(result); }
private void ReaderToProperty(System.Data.IDataReader reader, object obj, ReadProperty rp, PropertyMapper pm, PropertyHandler handler) { try { object dbvalue = reader[rp.Index]; if (dbvalue != DBNull.Value) { if (pm.Cast != null) { dbvalue = pm.Cast.ToProperty(dbvalue, pm.Handler.Property.PropertyType, obj); } handler.Set(obj, Uility.ChangeType(dbvalue, pm.Handler.Property.PropertyType)); } } catch (Exception e_) { throw new PeanutException(string.Format(DataMsg.READER_TO_PROPERTY_ERROR, pm.ColumnName, pm.Handler.Property.Name), e_); } }
private void ReaderToProperty(System.Data.IDataReader reader, object obj, ReadProperty p) { object dbvalue = null; try { if (p.Index >= 0) { dbvalue = reader[p.Index]; if (dbvalue != DBNull.Value) { if (p.Cast != null) { dbvalue = p.Cast.ToProperty(dbvalue, p.Handler.Property.PropertyType, null); } p.Handler.Set(obj, Uility.ChangeType(dbvalue, p.Handler.Property.PropertyType)); } } } catch (Exception e_) { throw new PeanutException(string.Format(DataMsg.READER_TO_PROPERTY_ERROR, dbvalue, p.Handler.Property.Name), e_); } }