Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no interface for SqlDataReader.ReadAsync()

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.

like image 944
Nathan Cooper Avatar asked Jun 12 '16 21:06

Nathan Cooper


1 Answers

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.

like image 173
Matías Fidemraizer Avatar answered Oct 13 '22 01:10

Matías Fidemraizer