是否可以在不支持分布式事务的情况下使用System.Transactions编程模型?
类似这样的东西。
TransactionConfig.DisablePromotion = true;
是否可以在不支持分布式事务的情况下使用System.Transactions编程模型?
类似这样的东西。
TransactionConfig.DisablePromotion = true;
using (new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted })) { // 访问另一个数据库 }
- Kirk Wollvar txOpts = new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TimeSpan.FromMinutes(10)};
using (var tx = new TransactionScope(TransactionScopeOption.Suppress, txOpts))
{
using (var db1 = new ObjectContext(connection1))
{
db1.Connection.Open();
using (var db1tx = db1.Connection.BeginTransaction(
System.Data.IsolationLevel.ReadCommitted))
{
using (var db2 = new ObjectContext(connection2))
{
db2.Connection.Open();
using (var db2tx = db2.Connection.BeginTransaction(
System.Data.IsolationLevel.ReadCommitted))
{
// do stuff
db1.SaveChanges(false);
db2.SaveChanges(false);
db1tx.Commit();
db2tx.Commit();
tx.Complete();
}
}
}
}
}