当前位置: 首页>>代码示例>>C#>>正文


C# TransactionScope.Commit方法代码示例

本文整理汇总了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();
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:45,代码来源:Fixture.cs

示例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();
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:31,代码来源:Fixture.cs

示例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();
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:22,代码来源:Fixture.cs

示例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();
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:21,代码来源:Fixture.cs

示例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();
			}
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:34,代码来源:Fixture.cs


注:本文中的System.Transactions.TransactionScope.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。