本文整理汇总了C#中Post.SaveWithException方法的典型用法代码示例。如果您正苦于以下问题:C# Post.SaveWithException方法的具体用法?C# Post.SaveWithException怎么用?C# Post.SaveWithException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post.SaveWithException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RollbackUponException
public void RollbackUponException()
{
using(var transaction = new TransactionScope())
{
var blog = new Blog {Author = "hammett", Name = "some name"};
blog.Save();
var post = new Post(blog, "title", "post contents", "Castle");
try
{
post.SaveWithException();
}
catch(Exception)
{
transaction.VoteRollBack();
}
}
using (new SessionScope()) {
var blogs = Blog.FindAll().ToArray();
Assert.AreEqual(0, blogs.Length);
var posts = Post.FindAll().ToArray();
Assert.AreEqual(0, posts.Length);
}
}
示例2: LotsOfNestedTransactionWithDifferentConfigurations
public void LotsOfNestedTransactionWithDifferentConfigurations()
{
using(var root = new TransactionScope())
{
using(var t1 = new TransactionScope()) // Isolated
{
var 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))
{
var post = new Post(blog, "title", "post contents", "Castle");
post.Save();
}
t1.VoteRollBack();
}
Blog.FindAll(); // Cant be locked
using(new TransactionScope())
{
var 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(var t1n = new TransactionScope(TransactionMode.Inherits))
{
var post = new Post(blog, "title", "post contents", "Castle");
try
{
post.SaveWithException();
}
catch(Exception)
{
t1n.VoteRollBack();
}
}
}
root.VoteCommit();
}
using (new SessionScope()) {
var blogs = Blog.FindAll().ToArray();
Assert.AreEqual(1, blogs.Length);
var posts = Post.FindAll().ToArray();
Assert.AreEqual(0, posts.Length);
}
}
示例3: NestedTransactionWithRollbackOnDispose
public void NestedTransactionWithRollbackOnDispose()
{
using(new TransactionScope())
{
var blog = new Blog();
using(var t1 = new TransactionScope(TransactionMode.Inherits, ondispose: OnDispose.Rollback))
{
blog.Author = "hammett";
blog.Name = "some name";
blog.Save();
t1.VoteCommit();
}
using(var t2 = new TransactionScope(TransactionMode.Inherits, ondispose: OnDispose.Rollback))
{
var post = new Post(blog, "title", "post contents", "Castle");
try
{
post.SaveWithException();
t2.VoteCommit(); // Will never be called
}
catch(Exception)
{
// t2.VoteRollBack();
}
}
}
using (new SessionScope()) {
var blogs = Blog.FindAll().ToArray();
Assert.AreEqual(0, blogs.Length);
var posts = Post.FindAll().ToArray();
Assert.AreEqual(0, posts.Length);
}
}