火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Castle AR with Transaction

Posted on 2006-10-15 20:30  剑廿三  阅读(213)  评论(0编辑  收藏  举报
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();
        }
    }