Create a gist now

Instantly share code, notes, and snippets.

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