Reputation: 7002
I am using ASP.Net Web Forms, .Net Framework 3.5, Entity Framework
In my application I am doing inserts using entity model and then calling SaveChanges()
, I know in this case Entity model handles the transactions and if any query fails, everything will be reverted.
But in few cases, I use a SQL-Server SP to insert data in different tables. This SP has 4 to 5 insert queries. I want to know that if any one query in SP fails, will Entity model revert the other queries or not? I don't think entity model will handle that - right? Is there any workaround or I'll have to use Entity model to insert data for handling transactions?
Upvotes: 1
Views: 1576
Reputation: 89745
Check this out
Entity Framework - Using Transactions or SaveChanges(false) and AcceptAllChanges()?
Upvotes: -1
Reputation: 32447
You can use the TransactionScope class. This will ensure an Atomic transaction
using (TransactionScope scope = new TransactionScope())
{
mySP.Insert();
context.SaveChanges();
scope.Complete();
}
Upvotes: 2