Added new cached reader to single file version

This commit is contained in:
2026-01-13 16:37:20 +01:00
parent ec548a79ab
commit 4847af02bd

View File

@@ -67,16 +67,23 @@ namespace DynamORM
{ {
#region Constructor and Data #region Constructor and Data
private DataTable _schema; private class Data
private int _fields; {
private int _rows; internal DataTable _schema;
private int _position; internal int _fields;
private int _cachePos; internal int _rows;
internal int _rowsAffected;
internal int _position = -1;
internal int _cachePos = -1;
private IList<string> _names; internal IList<string> _names;
private IDictionary<string, int> _ordinals; internal IDictionary<string, int> _ordinals;
private IList<Type> _types; internal IList<Type> _types;
private IList<object> _cache; internal IList<object> _cache;
}
private List<Data> _data = new List<Data>();
private int _currentDataPosition = 0;
private DynamicCachedReader() private DynamicCachedReader()
{ {
@@ -110,8 +117,12 @@ namespace DynamORM
var r = new DynamicCachedReader(); var r = new DynamicCachedReader();
r.Init(firstDict.Keys.Count); r.Init(firstDict.Keys.Count);
r._data.Add(new Data());
var data = r._data[r._currentDataPosition];
for (int i = 0; i < firstDict.Keys.Count; i++) for (int i = 0; i < firstDict.Keys.Count; i++)
r._types.Add(null); data._types.Add(null);
foreach (dynamic elem in (objects as IEnumerable<dynamic>)) foreach (dynamic elem in (objects as IEnumerable<dynamic>))
{ {
@@ -122,60 +133,60 @@ namespace DynamORM
{ {
object val = dict[k]; object val = dict[k];
r._cache.Add(val); data._cache.Add(val);
if (r._types[c] == null && val != null) if (data._types[c] == null && val != null)
r._types[c] = val.GetType(); data._types[c] = val.GetType();
c++; c++;
} }
r._rows++; data._rows++;
} }
for (int i = 0; i < firstDict.Keys.Count; i++) for (int i = 0; i < firstDict.Keys.Count; i++)
if (r._types[i] == null) if (data._types[i] == null)
r._types[i] = typeof(string); data._types[i] = typeof(string);
r._schema = new DataTable("DYNAMIC"); data._schema = new DataTable("DYNAMIC");
r._schema.Columns.Add(new DataColumn("ColumnName", typeof(string))); data._schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
r._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int))); data._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
r._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int))); data._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
r._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short))); data._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
r._schema.Columns.Add(new DataColumn("NumericScale", typeof(short))); data._schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
r._schema.Columns.Add(new DataColumn("DataType", typeof(Type))); data._schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
r._schema.Columns.Add(new DataColumn("ProviderType", typeof(int))); data._schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
r._schema.Columns.Add(new DataColumn("NativeType", typeof(int))); data._schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
r._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool))); data._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
r._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool))); data._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
r._schema.Columns.Add(new DataColumn("IsKey", typeof(bool))); data._schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
r._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool))); data._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
int ordinal = 0; int ordinal = 0;
DataRow dr = null; DataRow dr = null;
foreach (var column in firstDict.Keys) foreach (var column in firstDict.Keys)
{ {
dr = r._schema.NewRow(); dr = data._schema.NewRow();
dr[0] = column; dr[0] = column;
dr[1] = ordinal; dr[1] = ordinal;
dr[2] = 0; dr[2] = 0;
dr[3] = 0; dr[3] = 0;
dr[4] = 0; dr[4] = 0;
dr[5] = r._types[ordinal]; dr[5] = data._types[ordinal];
dr[6] = r._types[ordinal].ToDbType(); dr[6] = data._types[ordinal].ToDbType();
dr[7] = r._types[ordinal].ToDbType(); dr[7] = data._types[ordinal].ToDbType();
dr[8] = true; dr[8] = true;
dr[9] = false; dr[9] = false;
dr[10] = false; dr[10] = false;
dr[11] = false; dr[11] = false;
r._schema.Rows.Add(dr); data._schema.Rows.Add(dr);
r._names.Add(dr[0].ToString()); data._names.Add(dr[0].ToString());
r._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++); data._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
r._types.Add((Type)dr[5]); data._types.Add((Type)dr[5]);
dr.AcceptChanges(); dr.AcceptChanges();
} }
@@ -202,8 +213,6 @@ namespace DynamORM
r.FillFromEnumerable(objects, mapper); r.FillFromEnumerable(objects, mapper);
r.IsClosed = false; r.IsClosed = false;
r._position = -1;
r._cachePos = -1;
return r; return r;
} }
@@ -225,28 +234,30 @@ namespace DynamORM
r.FillFromEnumerable(elementType, objects, mapper); r.FillFromEnumerable(elementType, objects, mapper);
r.IsClosed = false; r.IsClosed = false;
r._position = -1;
r._cachePos = -1;
return r; return r;
} }
private void InitDataReader(IDataReader reader, int offset = 0, int limit = -1, Func<DynamicCachedReader, int, bool> progress = null) private void InitDataReader(IDataReader reader, int offset = 0, int limit = -1, Func<DynamicCachedReader, int, bool> progress = null)
{ {
_schema = reader.GetSchemaTable(); do
RecordsAffected = reader.RecordsAffected; {
Init(reader.FieldCount); Init(reader.FieldCount);
var data = _data[_currentDataPosition];
data._schema = reader.GetSchemaTable();
data._rowsAffected = reader.RecordsAffected;
int i = 0; int i = 0;
for (i = 0; i < _fields; i++) for (i = 0; i < data._fields; i++)
{ {
_names.Add(reader.GetName(i)); data._names.Add(reader.GetName(i));
_types.Add(reader.GetFieldType(i)); data._types.Add(reader.GetFieldType(i));
if (!_ordinals.ContainsKey(reader.GetName(i).ToUpper())) if (!data._ordinals.ContainsKey(reader.GetName(i).ToUpper()))
_ordinals.Add(reader.GetName(i).ToUpper(), i); data._ordinals.Add(reader.GetName(i).ToUpper(), i);
} }
int current = 0; int current = 0;
@@ -258,31 +269,33 @@ namespace DynamORM
continue; continue;
} }
for (i = 0; i < _fields; i++) for (i = 0; i < data._fields; i++)
_cache.Add(reader[i]); data._cache.Add(reader[i]);
_rows++; data._rows++;
current++; current++;
if (limit >= 0 && _rows >= limit) if (limit >= 0 && data._rows >= limit)
break; break;
if (progress != null && !progress(this, _rows)) if (progress != null && !progress(this, data._rows))
break; break;
} }
IsClosed = false; IsClosed = false;
_position = -1; data._position = -1;
_cachePos = -1; data._cachePos = -1;
if (progress != null) if (progress != null)
progress(this, _rows); progress(this, data._rows);
} while (reader.NextResult());
reader.Close(); reader.Close();
} }
private void FillFromEnumerable<T>(IEnumerable<T> objects, DynamicTypeMap mapper) private void FillFromEnumerable<T>(IEnumerable<T> objects, DynamicTypeMap mapper)
{ {
var data = _data[_currentDataPosition];
foreach (var elem in objects) foreach (var elem in objects)
{ {
foreach (var col in mapper.ColumnsMap) foreach (var col in mapper.ColumnsMap)
@@ -292,17 +305,19 @@ namespace DynamORM
if (col.Value.Get != null) if (col.Value.Get != null)
val = col.Value.Get(elem); val = col.Value.Get(elem);
_cache.Add(val); data._cache.Add(val);
} }
_cache.Add(elem); data._cache.Add(elem);
_rows++; data._rows++;
} }
} }
private void FillFromEnumerable(Type elementType, IEnumerable objects, DynamicTypeMap mapper) private void FillFromEnumerable(Type elementType, IEnumerable objects, DynamicTypeMap mapper)
{ {
var data = _data[_currentDataPosition];
foreach (var elem in objects) foreach (var elem in objects)
{ {
foreach (var col in mapper.ColumnsMap) foreach (var col in mapper.ColumnsMap)
@@ -312,37 +327,38 @@ namespace DynamORM
if (col.Value.Get != null) if (col.Value.Get != null)
val = col.Value.Get(elem); val = col.Value.Get(elem);
_cache.Add(val); data._cache.Add(val);
} }
_cache.Add(elem); data._cache.Add(elem);
_rows++; data._rows++;
} }
} }
private void CreateSchemaTable(DynamicTypeMap mapper) private void CreateSchemaTable(DynamicTypeMap mapper)
{ {
_schema = new DataTable("DYNAMIC"); var data = _data[_currentDataPosition];
_schema.Columns.Add(new DataColumn("ColumnName", typeof(string))); data._schema = new DataTable("DYNAMIC");
_schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int))); data._schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
_schema.Columns.Add(new DataColumn("ColumnSize", typeof(int))); data._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
_schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short))); data._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
_schema.Columns.Add(new DataColumn("NumericScale", typeof(short))); data._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
_schema.Columns.Add(new DataColumn("DataType", typeof(Type))); data._schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
_schema.Columns.Add(new DataColumn("ProviderType", typeof(int))); data._schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
_schema.Columns.Add(new DataColumn("NativeType", typeof(int))); data._schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
_schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool))); data._schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
_schema.Columns.Add(new DataColumn("IsUnique", typeof(bool))); data._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
_schema.Columns.Add(new DataColumn("IsKey", typeof(bool))); data._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
_schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool))); data._schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
data._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
int ordinal = 0; int ordinal = 0;
DataRow dr = null; DataRow dr = null;
foreach (var column in mapper.ColumnsMap) foreach (var column in mapper.ColumnsMap)
{ {
dr = _schema.NewRow(); dr = data._schema.NewRow();
dr[0] = column.Value.Column.NullOr(x => x.Name ?? column.Value.Name, column.Value.Name); dr[0] = column.Value.Column.NullOr(x => x.Name ?? column.Value.Name, column.Value.Name);
dr[1] = ordinal; dr[1] = ordinal;
@@ -357,16 +373,16 @@ namespace DynamORM
dr[10] = column.Value.Column.NullOr(x => x.IsKey, false); dr[10] = column.Value.Column.NullOr(x => x.IsKey, false);
dr[11] = false; dr[11] = false;
_schema.Rows.Add(dr); data._schema.Rows.Add(dr);
_names.Add(dr[0].ToString()); data._names.Add(dr[0].ToString());
_ordinals.Add(dr[0].ToString().ToUpper(), ordinal++); data._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
_types.Add((Type)dr[5]); data._types.Add((Type)dr[5]);
dr.AcceptChanges(); dr.AcceptChanges();
} }
dr = _schema.NewRow(); dr = data._schema.NewRow();
dr[0] = "#O"; dr[0] = "#O";
dr[1] = ordinal; dr[1] = ordinal;
@@ -381,33 +397,38 @@ namespace DynamORM
dr[10] = false; dr[10] = false;
dr[11] = false; dr[11] = false;
_schema.Rows.Add(dr); data._schema.Rows.Add(dr);
_names.Add("#O"); data._names.Add("#O");
_ordinals.Add("#O".ToUpper(), ordinal++); data._ordinals.Add("#O".ToUpper(), ordinal++);
_types.Add(mapper.Type); data._types.Add(mapper.Type);
dr.AcceptChanges(); dr.AcceptChanges();
} }
private void Init(int fieldCount) private void Init(int fieldCount)
{ {
_rows = 0; _data.Add(new Data()
_fields = fieldCount; {
_names = new List<string>(_fields); _rows = 0,
_ordinals = new Dictionary<string, int>(_fields); _fields = fieldCount,
_types = new List<Type>(_fields); _names = new List<string>(fieldCount),
_cache = new List<object>(_fields * 100); _ordinals = new Dictionary<string, int>(fieldCount),
_types = new List<Type>(fieldCount),
_cache = new List<object>(fieldCount * 100),
});
_currentDataPosition = _data.Count - 1;
} }
/// <summary>Sets the current position in reader.</summary> /// <summary>Sets the current position in reader.</summary>
/// <param name="pos">The position.</param> /// <param name="pos">The position.</param>
public void SetPosition(int pos) public void SetPosition(int pos)
{ {
if (pos >= -1 && pos < _rows) if (pos >= -1 && pos < _data[_currentDataPosition]._rows)
{ {
_position = pos; _data[_currentDataPosition]._position = pos;
_cachePos = _position * _fields; _data[_currentDataPosition]._cachePos = _data[_currentDataPosition]._position * _data[_currentDataPosition]._fields;
} }
else else
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
@@ -421,15 +442,14 @@ namespace DynamORM
public void Close() public void Close()
{ {
IsClosed = true; IsClosed = true;
_position = _rows; _currentDataPosition = -1;
_cachePos = -1;
} }
/// <summary>Gets a value indicating the depth of nesting for the current row.</summary> /// <summary>Gets a value indicating the depth of nesting for the current row.</summary>
/// <remarks>This implementation use this field to indicate row count.</remarks> /// <remarks>This implementation use this field to indicate row count.</remarks>
public int Depth public int Depth
{ {
get { return _rows; } get { return _data[_currentDataPosition]._rows; }
} }
/// <summary>Returns a System.Data.DataTable that describes the column metadata of the /// <summary>Returns a System.Data.DataTable that describes the column metadata of the
@@ -438,7 +458,7 @@ namespace DynamORM
/// The System.Data.IDataReader is closed.</exception> /// The System.Data.IDataReader is closed.</exception>
public DataTable GetSchemaTable() public DataTable GetSchemaTable()
{ {
return _schema; return _data[_currentDataPosition]._schema;
} }
/// <summary>Gets a value indicating whether the data reader is closed.</summary> /// <summary>Gets a value indicating whether the data reader is closed.</summary>
@@ -448,24 +468,26 @@ namespace DynamORM
/// <returns>Returns true if there are more rows; otherwise, false.</returns> /// <returns>Returns true if there are more rows; otherwise, false.</returns>
public bool NextResult() public bool NextResult()
{ {
_cachePos = (++_position) * _fields; _currentDataPosition++;
return _position < _rows; return _data.Count < _currentDataPosition;
} }
/// <summary>Advances the System.Data.IDataReader to the next record.</summary> /// <summary>Advances the System.Data.IDataReader to the next record.</summary>
/// <returns>Returns true if there are more rows; otherwise, false.</returns> /// <returns>Returns true if there are more rows; otherwise, false.</returns>
public bool Read() public bool Read()
{ {
_cachePos = (++_position) * _fields; var data = _data[_currentDataPosition];
return _position < _rows; data._cachePos = (++data._position) * data._fields;
return data._position < data._rows;
} }
/// <summary>Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.</summary> /// <summary>Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.</summary>
/// <returns>The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement /// <returns>The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement
/// failed; and -1 for SELECT statements.</returns> /// failed; and -1 for SELECT statements.</returns>
public int RecordsAffected { get; private set; } public int RecordsAffected { get { return _data[_currentDataPosition]._rowsAffected; } }
#endregion IDataReader Members #endregion IDataReader Members
@@ -475,10 +497,15 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary> /// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose() public void Dispose()
{ {
_names.Clear(); foreach (var data in _data)
_types.Clear(); {
_cache.Clear(); data._names.Clear();
_schema.Dispose(); data._types.Clear();
data._cache.Clear();
data._schema.Dispose();
}
_data.Clear();
} }
#endregion IDisposable Members #endregion IDisposable Members
@@ -487,14 +514,15 @@ namespace DynamORM
/// <summary>Gets the number of columns in the current row.</summary> /// <summary>Gets the number of columns in the current row.</summary>
/// <remarks>When not positioned in a valid record set, 0; otherwise, the number of columns in the current record. The default is -1.</remarks> /// <remarks>When not positioned in a valid record set, 0; otherwise, the number of columns in the current record. The default is -1.</remarks>
public int FieldCount { get { return _fields; } } public int FieldCount { get { return _data[_currentDataPosition]._fields; } }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
/// <param name="i">The index of the field to find.</param> /// <param name="i">The index of the field to find.</param>
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public bool GetBoolean(int i) public bool GetBoolean(int i)
{ {
return (bool)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (bool)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -502,7 +530,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public byte GetByte(int i) public byte GetByte(int i)
{ {
return (byte)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (byte)data._cache[data._cachePos + i];
} }
/// <summary>Reads a stream of bytes from the specified column offset into the buffer /// <summary>Reads a stream of bytes from the specified column offset into the buffer
@@ -515,7 +544,9 @@ namespace DynamORM
/// <returns>The actual number of bytes read.</returns> /// <returns>The actual number of bytes read.</returns>
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
{ {
using (MemoryStream ms = new MemoryStream((byte[])_cache[_cachePos + i])) var data = _data[_currentDataPosition];
using (MemoryStream ms = new MemoryStream((byte[])data._cache[data._cachePos + i]))
return ms.Read(buffer, bufferoffset, length); return ms.Read(buffer, bufferoffset, length);
} }
@@ -524,7 +555,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public char GetChar(int i) public char GetChar(int i)
{ {
return (char)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (char)data._cache[data._cachePos + i];
} }
/// <summary>Reads a stream of characters from the specified column offset into the buffer /// <summary>Reads a stream of characters from the specified column offset into the buffer
@@ -537,7 +569,9 @@ namespace DynamORM
/// <returns>The actual number of characters read.</returns> /// <returns>The actual number of characters read.</returns>
public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
{ {
using (MemoryStream ms = new MemoryStream((byte[])_cache[_cachePos + i])) var data = _data[_currentDataPosition];
using (MemoryStream ms = new MemoryStream((byte[])data._cache[data._cachePos + i]))
{ {
byte[] buff = new byte[buffer.Length]; byte[] buff = new byte[buffer.Length];
long ret = ms.Read(buff, bufferoffset, length); long ret = ms.Read(buff, bufferoffset, length);
@@ -562,7 +596,7 @@ namespace DynamORM
/// <returns>The data type information for the specified field.</returns> /// <returns>The data type information for the specified field.</returns>
public string GetDataTypeName(int i) public string GetDataTypeName(int i)
{ {
return _types[i].Name; return _data[_currentDataPosition]._types[i].Name;
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -570,7 +604,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public DateTime GetDateTime(int i) public DateTime GetDateTime(int i)
{ {
return (DateTime)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (DateTime)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -578,7 +613,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public decimal GetDecimal(int i) public decimal GetDecimal(int i)
{ {
return (decimal)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (decimal)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -586,7 +622,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public double GetDouble(int i) public double GetDouble(int i)
{ {
return (double)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (double)data._cache[data._cachePos + i];
} }
/// <summary>Gets the System.Type information corresponding to the type of System.Object /// <summary>Gets the System.Type information corresponding to the type of System.Object
@@ -596,7 +633,7 @@ namespace DynamORM
/// would be returned from System.Data.IDataRecord.GetValue(System.Int32).</returns> /// would be returned from System.Data.IDataRecord.GetValue(System.Int32).</returns>
public Type GetFieldType(int i) public Type GetFieldType(int i)
{ {
return _types[i]; return _data[_currentDataPosition]._types[i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -604,7 +641,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public float GetFloat(int i) public float GetFloat(int i)
{ {
return (float)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (float)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -612,7 +650,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public Guid GetGuid(int i) public Guid GetGuid(int i)
{ {
return (Guid)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (Guid)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -620,7 +659,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public short GetInt16(int i) public short GetInt16(int i)
{ {
return (short)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (short)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -628,7 +668,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public int GetInt32(int i) public int GetInt32(int i)
{ {
return (int)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (int)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -636,7 +677,8 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public long GetInt64(int i) public long GetInt64(int i)
{ {
return (long)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (long)data._cache[data._cachePos + i];
} }
/// <summary>Gets the name for the field to find.</summary> /// <summary>Gets the name for the field to find.</summary>
@@ -644,7 +686,7 @@ namespace DynamORM
/// <returns>The name of the field or the empty string (""), if there is no value to return.</returns> /// <returns>The name of the field or the empty string (""), if there is no value to return.</returns>
public string GetName(int i) public string GetName(int i)
{ {
return _names[i]; return _data[_currentDataPosition]._names[i];
} }
/// <summary>Return the index of the named field.</summary> /// <summary>Return the index of the named field.</summary>
@@ -652,8 +694,10 @@ namespace DynamORM
/// <returns>The index of the named field.</returns> /// <returns>The index of the named field.</returns>
public int GetOrdinal(string name) public int GetOrdinal(string name)
{ {
if (_ordinals.ContainsKey(name.ToUpper())) var data = _data[_currentDataPosition];
return _ordinals[name.ToUpper()];
if (data._ordinals.ContainsKey(name.ToUpper()))
return data._ordinals[name.ToUpper()];
return -1; return -1;
} }
@@ -663,7 +707,9 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public string GetString(int i) public string GetString(int i)
{ {
return (string)_cache[_cachePos + i]; var data = _data[_currentDataPosition];
return (string)data._cache[data._cachePos + i];
} }
/// <summary>Return the value of the specified field.</summary> /// <summary>Return the value of the specified field.</summary>
@@ -671,7 +717,9 @@ namespace DynamORM
/// <returns>Field value upon return.</returns> /// <returns>Field value upon return.</returns>
public object GetValue(int i) public object GetValue(int i)
{ {
return _cache[_cachePos + i]; var data = _data[_currentDataPosition];
return data._cache[data._cachePos + i];
} }
/// <summary>Gets all the attribute fields in the collection for the current record.</summary> /// <summary>Gets all the attribute fields in the collection for the current record.</summary>
@@ -679,10 +727,12 @@ namespace DynamORM
/// <returns>The number of instances of System.Object in the array.</returns> /// <returns>The number of instances of System.Object in the array.</returns>
public int GetValues(object[] values) public int GetValues(object[] values)
{ {
for (int i = 0; i < _fields; i++) var data = _data[_currentDataPosition];
values[i] = _cache[_cachePos + i];
return _fields; for (int i = 0; i < data._fields; i++)
values[i] = data._cache[data._cachePos + i];
return data._fields;
} }
/// <summary>Return whether the specified field is set to null.</summary> /// <summary>Return whether the specified field is set to null.</summary>
@@ -690,7 +740,8 @@ namespace DynamORM
/// <returns>Returns true if the specified field is set to null; otherwise, false.</returns> /// <returns>Returns true if the specified field is set to null; otherwise, false.</returns>
public bool IsDBNull(int i) public bool IsDBNull(int i)
{ {
return _cache[_cachePos + i] == null || _cache[_cachePos + i] == DBNull.Value; var data = _data[_currentDataPosition];
return data._cache[data._cachePos + i] == null || data._cache[data._cachePos + i] == DBNull.Value;
} }
/// <summary>Gets or sets specified value in current record.</summary> /// <summary>Gets or sets specified value in current record.</summary>
@@ -700,8 +751,10 @@ namespace DynamORM
{ {
get get
{ {
if (_ordinals.ContainsKey(name.ToUpper())) var data = _data[_currentDataPosition];
return _cache[_cachePos + _ordinals[name.ToUpper()]];
if (data._ordinals.ContainsKey(name.ToUpper()))
return data._cache[data._cachePos + data._ordinals[name.ToUpper()]];
throw new IndexOutOfRangeException(String.Format("Field '{0}' not found.", name)); throw new IndexOutOfRangeException(String.Format("Field '{0}' not found.", name));
} }
@@ -712,7 +765,11 @@ namespace DynamORM
/// <returns>Value of specified column.</returns> /// <returns>Value of specified column.</returns>
public object this[int i] public object this[int i]
{ {
get { return _cache[_cachePos + i]; } get
{
var data = _data[_currentDataPosition];
return data._cache[data._cachePos + i];
}
} }
#endregion IDataRecord Members #endregion IDataRecord Members