I recommend treating DbCommand
and his friends as if they were interfaces when using the database APIs. For the sake of generalizing the API for different database providers, DbCommand
achieves exactly the same as IDbCommand
— or perhaps better, because it includes newer technologies such as await
Task
*Async()
.
MS can not add any new methods with new functionality in IDbCommand
. If they added a method to IDbCommand
, this would be a change, since anyone can implement this interface in their code, and MS has put a lot of effort into maintaining ABI and API compatibility within the framework. If they extended the interfaces in the .net release, client code that previously worked stopped compiling, and existing assemblies that were not recompiled would encounter runtime errors. In addition, they cannot add the correct *Async()
or Begin*()
methods using extension methods without doing an ugly cast to DbCommand
backstage (which is the worst practice, fault security, and unnecessary implementation of dynamic execution at run time).
On the other hand, MS can add new virtual methods to DbCommand
without breaking the ABI. Adding new methods to the base class may be considered an API violation (compilation time, and not so bad for interruption as the runtime), because if you inherit DbCommand
and add a member with the same name, you will begin to receive warning CS0108: 'member1' hides the inherited member 'member2'. Use a new keyword if hiding was intended. ) Thus, DbCommand
can get new features with minimal impact on consumer code that follows best practices (for example, most materials will work until it works against the type system and calls methods using something like myCommand.GetType().GetMethods()[3].Invoke(myCommand, …)
).
A possible strategy that MS could use to support people who like interfaces would be to introduce new interfaces with names like IAsyncDbCommand
and have DbCommand
implement them. They did not do this. I don’t know why, but they probably didn’t, because it would increase the complication, and the alternative to direct consumption of DbCommand
provides most of the advantages for using interfaces with a few minuses. Ie, this will work with a small return.
binki source share