Problem with VerticaCommand.Connection and .Transaction
It looks like there is a problem with the validation code in the setters of these two properties. If I set the connection and then the transaction, all is fine. But if I try to set the transaction first - it throws an InvalidOperationException with a message saying that the transaction's connection and the VerticaCommand's connection must be the same. It makes sense - the connection property is still null. It reveals a flaw in the base class DbCommand - allows dependency between the properties. The solution is simple - do it in the right order, however I do not have access to the calling code that does this. It works with SqlServer. My solution was to wrap the VerticaCommand class in MyVerticaCommand; allow for any transactions if the connection is null and store it in a temp. field; and when they set the connection - compare it with the Transaction's connection and if not the same - throw the exception, otherwise set both in the right order.
I am hoping that in spite of this being a small problem it can be fixed and I can get rid of the silly MyVerticaCommand class in my code.
Thanks
Val
Comments
Sure. Basically my wrapper inherits from DbCommand and has a private field _command of type VerticaCommand - it is instantiated in the constructor of my class. The class has also a temporary field _transaction of type VerticaTransaction which temporarily caches the transaction object. Pretty much every virtual property and method delegates the call to the field _command with exception of the properties Connection and Transaction where I fxied as explained above the problem with setting these properties in any order. I guess the right thing for the VerticaCommand is to do something similar: allow setting the transaction only if the connection is null or is enlisted in the same transaction; and also similarly allow setting the connection only if the transaction is null or equal to the transaction of the connection.