http://terrylee.vcblog.net/archive/2006/06/24/368471.html
using(TransactionScope tran = new TransactionScope())
{
try
{
for(int i=1;i<5;i++)
{
//创建Post对象
Post post = new Post();
post.Title="This is my "+i.ToString()+" post";
post.Category="Castle";
//注释掉这句
//post.Save();
blog.Posts.Add(post);
}
blog.Update();
tran.VoteCommit();
}
catch
{
tran.VoteRollBack();
}
}
{
try
{
for(int i=1;i<5;i++)
{
//创建Post对象
Post post = new Post();
post.Title="This is my "+i.ToString()+" post";
post.Category="Castle";
//注释掉这句
//post.Save();
blog.Posts.Add(post);
}
blog.Update();
tran.VoteCommit();
}
catch
{
tran.VoteRollBack();
}
}