本文整理汇总了C#中System.Transactions.TransactionScope.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope.Commit方法的具体用法?C# TransactionScope.Commit怎么用?C# TransactionScope.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Transactions.TransactionScope
的用法示例。
在下文中一共展示了TransactionScope.Commit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_commiting_items_in_DTC_transaction_will_add_items_to_2nd_level_cache
public void When_commiting_items_in_DTC_transaction_will_add_items_to_2nd_level_cache()
{
using (var tx = new TransactionScope())
{
using (var s = sessions.OpenSession())
{
s.Save(new Nums {ID = 29, NumA = 1, NumB = 3});
}
tx.Complete();
}
using (var tx = new TransactionScope())
{
using (var s = sessions.OpenSession())
{
var nums = s.Load<Nums>(29);
Assert.AreEqual(1, nums.NumA);
Assert.AreEqual(3, nums.NumB);
}
tx.Complete();
}
//closing the connection to ensure we can't really use it.
var connection = sessions.ConnectionProvider.GetConnection();
sessions.ConnectionProvider.CloseConnection(connection);
using (var tx = new TransactionScope())
{
using (var s = sessions.OpenSession(connection))
{
var nums = s.Load<Nums>(29);
Assert.AreEqual(1, nums.NumA);
Assert.AreEqual(3, nums.NumB);
}
tx.Complete();
}
using (var s = sessions.OpenSession())
using (var tx = s.BeginTransaction())
{
var nums = s.Load<Nums>(29);
s.Delete(nums);
tx.Commit();
}
}
示例2: When_using_two_sessions
public void When_using_two_sessions()
{
object id1, id2;
using (var tx = new TransactionScope())
{
using (ISession s1 = sessions.OpenSession())
using (ISession s2 = sessions.OpenSession())
{
id1 = s1.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
id2 = s2.Save(new Nums { NumA = 1, NumB = 2, ID = 6 });
tx.Complete();
}
}
using (ISession s = sessions.OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Nums nums = s.Get<Nums>(id1);
Assert.IsNotNull(nums);
s.Delete(nums);
nums = s.Get<Nums>(id2);
Assert.IsNotNull(nums);
s.Delete(nums);
tx.Commit();
}
}
示例3: When_committing_transaction_scope_will_commit_transaction
public void When_committing_transaction_scope_will_commit_transaction()
{
object id;
using (var tx = new TransactionScope())
{
using (ISession s = sessions.OpenSession())
{
id = s.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
}
tx.Complete();
}
using (ISession s = sessions.OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Nums nums = s.Get<Nums>(id);
Assert.IsNotNull(nums);
s.Delete(nums);
tx.Commit();
}
}
示例4: Will_not_save_when_flush_mode_is_never
public void Will_not_save_when_flush_mode_is_never()
{
object id;
using (var tx = new TransactionScope())
{
using (ISession s = sessions.OpenSession())
{
s.FlushMode = FlushMode.Never;
id = s.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
}
tx.Complete();
}
using (ISession s = sessions.OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Nums nums = s.Get<Nums>(id);
Assert.IsNull(nums);
tx.Commit();
}
}
示例5: When_using_two_sessions
public void When_using_two_sessions()
{
if (!TestDialect.SupportsConcurrentTransactions)
Assert.Ignore(Dialect.GetType().Name + " does not support concurrent transactions.");
object id1, id2;
using (var tx = new TransactionScope())
{
using (ISession s1 = sessions.OpenSession())
using (ISession s2 = sessions.OpenSession())
{
id1 = s1.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
id2 = s2.Save(new Nums { NumA = 1, NumB = 2, ID = 6 });
tx.Complete();
}
}
using (ISession s = sessions.OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
Nums nums = s.Get<Nums>(id1);
Assert.IsNotNull(nums);
s.Delete(nums);
nums = s.Get<Nums>(id2);
Assert.IsNotNull(nums);
s.Delete(nums);
tx.Commit();
}
}