一般来说,是否有一个接口表明TransactionScope
-awareness?是否有可用的常用数据库列表TransactionScope
?(它是扩展DbConnection或实现IDbConnection的任何东西吗?)
TransactionScope
与合作的数据库有什么关系?即,是否TransactionScope
以某种方式搜索活动连接并调用适当的开始/提交/回滚方法?数据库是否寻找环境TransactionScope
变量?或两者?
如有必要,背景。我正在处理一个旧的 DAL,它利用了一些不同的类似事务的策略:
//
// transactionless queries
//
// Microsoft.Practices.EnterpriseLibrary.Data. ...
Database db = SQLHelper.GetDatabase();
DbCommand cmd = db.GetStoredProcComment("doSomething");
db.AddInParameter(cmd, "p1", DbType.Guid, Id);
using (IDataReader r = db.ExecuteReader())
{
// etc.
}
//
// Transaction objects being passed around and attached to DbCommands
//
// somewhere up the line ...
DbConnection con = TransactionScopeConnections.GetConnection(db);
DbTransaction transaction = con.BeginTransaction();
// Microsoft.Practices.EnterpriseLibrary.Data. ...
Database db = SQLHelper.GetDatabase();
DbConnection con = TransactionScopeConnections.GetConnections(db);
DbCommand cmd = db.GetStoredProcComment("doSomething");
cmd.Transaction = transaction;
db.AddInParameter(cmd, "p1", DbType.Guid, Id);
using (IDataReader r = db.ExecuteReader())
{
// etc.
}
//
// queries in TransactionScopes
//
using (TransactionScope scope = new TransactionScope())
{
// Microsoft.Practices.EnterpriseLibrary.Data. ...
Database db = SQLHelper.GetDatabase();
DbCommand cmd = db.GetStoredProcComment("doSomething");
db.AddInParameter(cmd, "p1", DbType.Guid, Id);
using (IDataReader r = db.ExecuteReader())
{
// etc.
}
scope.Complete();
}
//
// both
//
Database db = SQLHelper.GetDatabase();
using (TransactionScope transactionScope = new TransactionScope())
{
DbConnection con = TransactionScopeConnections.GetConnection(db);
DbTransaction transaction = con.BeginTransaction();
/* ... build query ... */
query.transaction = transaction;
/* ... execute query, read results, if any ... */
transaction.Commit();
transactionScope.Complete();
}
这些都是企业库的有效选项吗?TransactionScope
表格没有意义吗?最后一种形式可能是多余的吗?