Search code examples
entity-frameworktransactional

Is EntityFrameworks AddRange Method Transactional


When I use the AddRange method from the Entity Framework and then call SaveChanges, if one of the Entities fails to be inserted into the DB, will everything be rollbacked?

I don't want to use explicit Transactions.


Solution

  • From msdn doc:

    SaveChanges operates within a transaction. SaveChanges will roll back that transaction and throw an exception if any of the dirty ObjectStateEntry objects cannot be persisted.

    https://msdn.microsoft.com/en-us/library/bb336792(v=vs.110).aspx

    I hope it helps!