EF中的事务处理

命名空间System.Transactions;

using (TransactionScope scope = new TransactionScope())
{
//Do something with context1
//Do something with context2

//Save Changes but don't discard yet
context1.SaveChanges(false);

//Save Changes but don't discard yet
context2.SaveChanges(false);

//if we get here things are looking good.
scope.Complete();
context1.AcceptAllChanges();
context2.AcceptAllChanges();

}

 

 

摘自:http://blog.csdn.net/yanwushu/article/details/10307801

posted @ 2015-07-07 10:54  今天起个早  阅读(171)  评论(0编辑  收藏  举报