Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does EF5 DbContext.SaveChanges handle transaction commit and rollback?

I am not clear on whether I need to use TransactionScope or DbContext.SaveChanges() is enough to commit my transaction consisting of multiple CRUD operations. I am using SQL Server in the backend.

like image 356
Jas Avatar asked Jun 25 '13 15:06

Jas


1 Answers

If you are calling SaveChanges() multiple times, and want to roll back all of those changes, yes you would want to use a TransactionScope. If you are calling SaveChanges() once on the context, all your changes are pushed to the database at once in a transaction behind the scenes.

like image 52
Steven V Avatar answered Sep 19 '22 16:09

Steven V