SafeDataReader: why it derives not from DbDataReader

SafeDataReader: why it derives not from DbDataReader

Old forum URL: forums.lhotka.net/forums/t/8020.aspx


Regent posted on Thursday, November 19, 2009

I'm just wondering why does SafeDataReader implements IDbDataReader rather than DbDataReader? DbDataReader required to implement methods like GetString, GetValue, Read, GetDecimal, etc. But also some additional properties like 'bool HasRows' or 'this[string name]' indexer.

Changing to DbDataReader base class will require to change all IDbConnection's and IDbTransaction's to DbConnection's and DbTransaction's but the good thing is that back in ConnectionManager, DbProviderFactory's CreateConnection method creates DbConnection instance...

RockfordLhotka replied on Friday, November 20, 2009

I haven't looked at DbDataReader, so I'm just guessing here. But I imagine a DbDataReader actually is a data reader, while SafeDataReader is a wrapper around a data reader. SafeDataReader isn't a data reader, it just contains one and delegates to it.

Adding more features (like the ones you list) to SafeDataReader is not a bad idea though.

Regent replied on Friday, November 20, 2009

Yes it is a wrapper but up to the moment it delegates less than a real DbDataReader would provide. DbDataReader is just an abstract class with a reasonable starting member's set each reader should be capable of handling...

Copyright (c) Marimer LLC