本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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 );
}
示例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());
}
示例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());
}