Skip to content

Instantly share code, notes, and snippets.

@PawelGerr
Created April 7, 2016 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PawelGerr/d1136aee09e5a651917c2bb2aaa1d8de to your computer and use it in GitHub Desktop.
Save PawelGerr/d1136aee09e5a651917c2bb2aaa1d8de to your computer and use it in GitHub Desktop.
public abstract class BulkInsertDataReader<T> : IDataReader
{
private readonly IReadOnlyCollection<SqlBulkCopyColumnMapping> _columnMappings;
private readonly IEnumerator<T> _enumerator;
protected T Current { get; private set; }
public int Depth { get; private set; }
public bool IsClosed { get; private set; }
public int RecordsAffected { get; private set; }
public int FieldCount
{
get { return _columnMappings.Count; }
}
protected BulkInsertDataReader(IReadOnlyCollection<SqlBulkCopyColumnMapping> columnMappings, IEnumerable<T> records)
{
_columnMappings = columnMappings;
_enumerator = records.GetEnumerator();
}
public bool Read()
{
bool hasMore = _enumerator.MoveNext();
Current = _enumerator.Current;
return hasMore;
}
public void Dispose()
{
_enumerator.Dispose();
Current = default(T);
}
public void Close()
{
IsClosed = true;
}
public IEnumerable<SqlBulkCopyColumnMapping> GetColumnMappings()
{
return _columnMappings;
}
public abstract object GetValue(int i);
// The following methods are not needed for SqlBulkCopy. Implement them on demand.
public string GetName(int i)
{
throw new NotImplementedException();
}
public string GetDataTypeName(int i)
{
throw new NotImplementedException();
}
public Type GetFieldType(int i)
{
throw new NotImplementedException();
}
public int GetValues(object[] values)
{
throw new NotImplementedException();
}
public int GetOrdinal(string name)
{
throw new NotImplementedException();
}
public bool GetBoolean(int i)
{
throw new NotImplementedException();
}
public byte GetByte(int i)
{
throw new NotImplementedException();
}
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
public char GetChar(int i)
{
throw new NotImplementedException();
}
public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
public Guid GetGuid(int i)
{
throw new NotImplementedException();
}
public short GetInt16(int i)
{
throw new NotImplementedException();
}
public int GetInt32(int i)
{
throw new NotImplementedException();
}
public long GetInt64(int i)
{
throw new NotImplementedException();
}
public float GetFloat(int i)
{
throw new NotImplementedException();
}
public double GetDouble(int i)
{
throw new NotImplementedException();
}
public string GetString(int i)
{
throw new NotImplementedException();
}
public decimal GetDecimal(int i)
{
throw new NotImplementedException();
}
public DateTime GetDateTime(int i)
{
throw new NotImplementedException();
}
public IDataReader GetData(int i)
{
throw new NotImplementedException();
}
public bool IsDBNull(int i)
{
throw new NotImplementedException();
}
object IDataRecord.this[int i]
{
get { throw new NotImplementedException(); }
}
object IDataRecord.this[string name]
{
get { throw new NotImplementedException(); }
}
public DataTable GetSchemaTable()
{
throw new NotImplementedException();
}
public bool NextResult()
{
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment