MVC EF4 SP roolback
my app type is MVC Application. and DB is SQL SERVER 2008. Every operation on DataBase tables are going 开发者_如何转开发with Stored Procedures. in one page i am going to add new rows to two different tables with two different stored procedures. between this tables has relation. in my [Post]Create() Action i call both of this SP. but my problem is: if any of this stored procedures executed with no success then roolback. No any rows must inserted no to first table no to the second table. How i can do this process?
To my ViewModel includes both of this tables...
Consider using TransactionScope
using (var scope = new new TransactionScope())
using (var context = new MyDbContext())
{
contex.SP1();
contex.SP2();
scope.Complete();
}
精彩评论