How can you execute multiple DbCommands with one connection?
Example:
var db = DatabaseFactory.CreateDatabase开发者_开发技巧();
var dbCommand = db.GetSqlStringCommand(InsertCommandText);
...
db.ExecuteNonQuery(dbCommand);
Now, I want to be able to Execute multiple dbCommands. For instance in pseudo kind of code:
var db = DatabaseFactory.CreateDatabase();
var dbCommand1 = db.GetSqlStringCommand(InsertCommandText);
...
var dbCommand1 = db.GetSqlStringCommand(InsertCommandText);
...
Adding both commands to db
Executing them
Each call to ExecuteNonQuery(DbCommand)
will potentially use a new connection. If you wanted to ensure that you were always using the same connection you could use the overload ExecuteNonQuery(DbCommand, DbTransaction)
. If you pass in a transaction Enterprise Library will use the connection associated with the transaction. Of course, you may not want to use a transaction if it is not required.
Maybe it would help to know why you want to only use one connection?
精彩评论