DataRowReader allows us to know how many columns where loaded but does not have an API to know number of loaded rows. This is an important missing API that is critical to have. As a workaround, I had to wrap my DataRowReader with a custom DataRowReader in order to get number of retireved rows as follows:
internal class DPDataRowReader : CustomDataRowReader
{
protected DataRowReader reader;
internal int affectedRows = -1;
internal DPDataRowReader(DataRowReader reader)
{
this.reader = reader;
}
protected override IEnumerable<DataRowReaderColumn> GetColumnsCore()
{
return this.reader.Columns;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void ResetCore()
{
this.reader.Reset();
}
protected override ResultProperties GetResultPropertiesCore()
{
return this.reader.ResultProperties;
}
protected override bool MoveNextCore()
{
affectedRows++;
return this.reader.MoveNext();
}
}
This works fine but it introduces an extra call for each retrieved row which may affect reader performance.
So the idea here is to add an API in DataRowReader to get number of retrieved rows.
Thanks,
Samer.