While SqlDataReader.Read() implements the IDataReader.Read(), there appears to no interface for SqlDataReader when using the async methods like ReadAsync().
Firstly, correct me if I'm wrong.
Is there a reason or justification for this? Is there something about the new async-await stuff that justifies lacking an interface here? It's just a bit baffling.
While the interface doesn't define the whole method, there's a common abstract class DbDataReader which defines ReadAsync.
Probably the most important reason to not include ReadAsync as part of IDataReader interface is to avoid a breaking change in terms of backwards compatibility.
If IDataReader in newer framework versions would force any data reader  to implement ReadAsync, any ADO.NET provider or framework relying on the so-called interface wouldn't be implementing it at all and these implementation would be broken.
Maybe they could use interface segregation principle and they could define a new interface called IDataReaderAsync which could provide asynchronous flavors of regular IDataReader members... But, at least, they've already provided a base class which is already derived by many framework classes:
System.Data.DataTableReader
System.Data.EntityClient.EntityDataReader
System.Data.Odbc.OdbcDataReader
System.Data.OleDb.OleDbDataReader
System.Data.OracleClient.OracleDataReader
System.Data.SqlClient.SqlDataReader
...and third-party ADO.NET providers' IDataReader might also derive DbDataReader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With