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


C# TransactionScope.VoteRollBack方法代码示例

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


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

示例1: RollbackVote

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

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

			using(TransactionScope transaction = new TransactionScope())
			{
				Blog blog = new Blog();
				blog.Author = "hammett";
				blog.Name = "some name";
				blog.Save();

				Post post = new Post(blog, "title", "post contents", "Castle");
				post.Save();

				// pretend something went wrong

				transaction.VoteRollBack();
			}

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

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

示例2: MixingSessionScopeAndTransactionScopes3

		public void MixingSessionScopeAndTransactionScopes3()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(PostLazy), typeof(BlogLazy));
			Recreate();

			PostLazy.DeleteAll();
			BlogLazy.DeleteAll();

			BlogLazy b = new BlogLazy();

			using(new SessionScope())
			{
				b.Name = "a";
				b.Author = "x";
				b.Save();

				using(new TransactionScope())
				{
					for(int i = 1; i <= 10; i++)
					{
						PostLazy post = new PostLazy(b, "t", "c", "General");
						post.Save();
					}
				}
			}

			using(new SessionScope())
			{
				// We should load this outside the transaction scope

				b = BlogLazy.Find(b.Id);

				using(TransactionScope transaction = new TransactionScope())
				{
					int total = b.Posts.Count;

					foreach(PostLazy p in b.Posts)
					{
						p.Delete();
					}

					b.Delete();

					transaction.VoteRollBack();
				}
			}

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

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

示例3: 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

示例4: NestedTransactions

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

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

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

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

					t1.VoteCommit();
				}

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

					try
					{
						post.SaveWithException();
					}
					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,代码行数:42,代码来源:TransactionScopeTestCase.cs

示例5: UsingTransactionScopeWithRollback

        public void UsingTransactionScopeWithRollback()
        {
            SqlConnection conn = CreateSqlConnection();
            ISession session1, session2;
            ITransaction trans1, trans2;

            using(TransactionScope scope = new TransactionScope())
            {
                Blog blog = new Blog();
                blog.Name = "hammett's blog";
                blog.Author = "hamilton verissimo";
                blog.Save();

                session1 = blog.CurrentSession;
                trans1 = blog.CurrentSession.Transaction;
                Assert.IsNotNull(session1);
                Assert.IsNotNull(session1.Transaction);
                Assert.IsFalse(session1.Transaction.WasCommitted);
                Assert.IsFalse(session1.Transaction.WasRolledBack);

                conn.Open();

                using(new DifferentDatabaseScope(conn))
                {
                    blog.Create();

                    session2 = blog.CurrentSession;
                    trans2 = blog.CurrentSession.Transaction;
                    Assert.IsNotNull(session2);

                    Assert.IsFalse( Object.ReferenceEquals(session1, session2) );

                    Assert.IsNotNull(session2.Transaction);
                    Assert.IsFalse(session2.Transaction.WasCommitted);
                    Assert.IsFalse(session2.Transaction.WasRolledBack);

                    scope.VoteRollBack();
                }
            }

            Assert.IsFalse(session1.IsOpen);
            Assert.IsFalse(session2.IsOpen);
            Assert.IsFalse(trans1.WasCommitted);
            Assert.IsTrue(trans1.WasRolledBack);
            Assert.IsFalse(trans2.WasCommitted);
            Assert.IsTrue(trans2.WasRolledBack);

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

            OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
            Assert.IsNotNull( blogs2 );
            Assert.AreEqual( 0, blogs2.Length );
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:55,代码来源:DifferentDatabaseScopeTestCase.cs

示例6: UsingNestedTransactionScopesWithRollback

        public void UsingNestedTransactionScopesWithRollback()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (new TransactionScope(TransactionMode.Inherits))
                {
                    new SSAFEntity("example").Save();
                    Assert.AreEqual(1, SSAFEntity.FindAll().Count());
                }
                Assert.AreEqual(1, SSAFEntity.FindAll().Count());
                scope.VoteRollBack();
            }

            using (new SessionScope())
                Assert.AreEqual(0, SSAFEntity.FindAll().Count());
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:16,代码来源:SessionScopeAutoflushTestCase.cs

示例7: UsingTransactionScopeWithRollbackAndInnerSessionScope

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


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