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


C# TransactionScope.VoteCommit方法代码示例

本文整理汇总了C#中TransactionScope.VoteCommit方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope.VoteCommit方法的具体用法?C# TransactionScope.VoteCommit怎么用?C# TransactionScope.VoteCommit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TransactionScope的用法示例。


在下文中一共展示了TransactionScope.VoteCommit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanIntegrateNHibernateAndActiveRecord

		public void CanIntegrateNHibernateAndActiveRecord()
		{
			ActiveRecordStarter.ModelsValidated += delegate
			{
				new ActiveRecordModelBuilder().CreateDummyModelFor(typeof(NHibernateClass));
			};
			ActiveRecordStarter.Initialize(
				GetConfigSource(),
				typeof(ActiveRecordClass),
				typeof(NHibernateClass));

			Recreate();

			using (TransactionScope tx = new TransactionScope())
			{
				ActiveRecordClass ar = new ActiveRecordClass();
				ar.Friend = new NHibernateClass();
				ActiveRecordMediator.Save(ar.Friend);
				ActiveRecordMediator.Save(ar);
				tx.VoteCommit();
			}

			using (TransactionScope tx = new TransactionScope())
			{
				ActiveRecordClass first = ActiveRecordMediator<ActiveRecordClass>.FindFirst();
				Assert.IsNotNull(first);
				Assert.IsNotNull(first.Friend);
			}
		}
开发者ID:joshrobb,项目名称:Castle.ActiveRecord,代码行数:29,代码来源:IntegrationWithNHibernateTestCase.cs

示例2: ExplicitFlushInsideSecondTransactionProblem

        public void ExplicitFlushInsideSecondTransactionProblem()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(),
                typeof(Company),
                typeof(Person),
                typeof(Blog),
                typeof(Post));
            Recreate();

            Company comp1 = new Company("comp1");
            Company comp2 = new Company("comp2");
            using(new SessionScope())
            {
                comp1.Create();
                comp2.Create();
            }

            using(new SessionScope(FlushAction.Never))
            {
                using(TransactionScope tx = new TransactionScope(OnDispose.Rollback))
                {
                    Company comp2a = Company.Find(comp2.Id);
                    comp2a.Name = "changed";
                    tx.VoteCommit();
                }

                using(new TransactionScope(OnDispose.Rollback))
                {
                    Company[] changedCompanies = ActiveRecordMediator<Company>.FindAllByProperty("Name", "changed");
                    Assert.AreEqual(1, changedCompanies.Length);
                    Company e2a = changedCompanies[0];
                    e2a.Delete();

                    SessionScope.Current.Flush();

                    Assert.AreEqual(0, ActiveRecordMediator<Company>.FindAllByProperty("Name", "changed").Length);
                }
            }
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:39,代码来源:TransactionScopeTestCase.cs

示例3: ValidateIsUniqueWithinTransactionScope

		public void ValidateIsUniqueWithinTransactionScope()
		{
			ActiveRecordStarter.Initialize( GetConfigSource(), typeof(Blog2) );
			Recreate();
			
			// The IsUniqueValidator was created a new SessionScope and causing an
			// error when used inside TransactionScope
			
			using (TransactionScope scope = new TransactionScope())
			{
				Blog2 blog = new Blog2();
				blog.Name = "A cool blog";
				blog.Create();
					
				blog = new Blog2();
				blog.Name = "Another cool blog";
				blog.Create();
				
				scope.VoteCommit();
			}
		}
开发者ID:jiangsf,项目名称:Castle.ActiveRecord,代码行数:21,代码来源:ValidationTestCase.cs

示例4: NestedTransactionWithRollbackOnDispose

		public void NestedTransactionWithRollbackOnDispose()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
			Recreate();

			Post.DeleteAll();
			Blog.DeleteAll();

			using(new TransactionScope())
			{
				Blog blog = new Blog();

				using(TransactionScope t1 = new TransactionScope(TransactionMode.Inherits, OnDispose.Rollback))
				{
					blog.Author = "hammett";
					blog.Name = "some name";
					blog.Save();

					t1.VoteCommit();
				}

				using(TransactionScope t2 = new TransactionScope(TransactionMode.Inherits, OnDispose.Rollback))
				{
					Post post = new Post(blog, "title", "post contents", "Castle");

					try
					{
						post.SaveWithException();

						t2.VoteCommit(); // Will never be called
					}
					catch(Exception)
					{
						// t2.VoteRollBack();
					}
				}
			}

			Blog[] blogs = Blog.FindAll();
			Assert.AreEqual(0, blogs.Length);

			Post[] posts = Post.FindAll();
			Assert.AreEqual(0, posts.Length);
		}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:44,代码来源:TransactionScopeTestCase.cs

示例5: MixingSessionScopeAndTransactionScopes

		public void MixingSessionScopeAndTransactionScopes()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
			Recreate();

			Post.DeleteAll();
			Blog.DeleteAll();

			using(new SessionScope())
			{
				using(TransactionScope root = new TransactionScope())
				{
					using(TransactionScope t1 = new TransactionScope()) // Isolated
					{
						Blog blog = new Blog();

						Blog.FindAll(); // Just to force a session association

						using(new TransactionScope(TransactionMode.Inherits))
						{
							Blog.FindAll(); // Just to force a session association

							blog.Author = "hammett";
							blog.Name = "some name";
							blog.Save();
						}

						using(new TransactionScope(TransactionMode.Inherits))
						{
							Post post = new Post(blog, "title", "post contents", "Castle");

							post.Save();
						}

						t1.VoteRollBack();
					}

					Blog.FindAll(); // Cant be locked

					using(new TransactionScope())
					{
						Blog blog = new Blog();
						Blog.FindAll(); // Just to force a session association

						using(new TransactionScope())
						{
							Blog.FindAll(); // Just to force a session association

							blog.Author = "hammett";
							blog.Name = "some name";
							blog.Save();
						}

						using(TransactionScope t1n = new TransactionScope(TransactionMode.Inherits))
						{
							Post post = new Post(blog, "title", "post contents", "Castle");

							try
							{
								post.SaveWithException();
							}
							catch(Exception)
							{
								t1n.VoteRollBack();
							}
						}
					}

					root.VoteCommit();
				}
			}

			Blog[] blogs = Blog.FindAll();
			Assert.AreEqual(1, blogs.Length);

			Post[] posts = Post.FindAll();
			Assert.AreEqual(0, posts.Length);
		}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:78,代码来源:TransactionScopeTestCase.cs

示例6: UsingTransactionScopeWithCommitAndInnerSessionScope

 public void UsingTransactionScopeWithCommitAndInnerSessionScope()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         using (new SessionScope())
         {
             new SSAFEntity("example").Save();
             Assert.AreEqual(1, SSAFEntity.FindAll().Count());
         }
         //Assert.AreEqual(1, SSAFEntity.FindAll().Length);
         scope.VoteCommit();
     }
     using (new SessionScope())
         Assert.AreEqual(1, SSAFEntity.FindAll().Count());
 }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:15,代码来源:SessionScopeAutoflushTestCase.cs


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