In addition to what Arthur said, a couple of points:
Diego
-
Perhaps your expectation is that DbContext itself would be transactional and that changes recorded in memory would be rolled back if the transaction fails on the database, but that is not the case. DbContext is designed (as Arthur explained) to help you collect in memory the changes that happen in your transactions but it is not transactional.
-
If by "run the process again" you mean that the way your application deals with the failure is to start the process "from scratch", i.e. by recording all the changes that need to be applied and entities that need to be added once more, then you should modify your application to throw away the DbContext instance used in the first try (which as Arthur mentioned, will be left ready to call SaveChanges again) and do this with a new (and empty) DbContext instance every time. Otherwise it is expected that you will end up with duplicate information added, and possibly with some failures for deletes and updates.
Diego