Multiple operations can be executed against a single transaction so that changes can be rolled back if any of the operations fail.
using (var context = new PlanetContext())
{
using (var transaction="/?originalUrl=https%3A%2F%2Friptutorial.com%2Fcontext.Database.BeginTransaction())%2520%2520%2520%2520%257B%2520%2520%2520%2520%2520%2520%2520%2520try%2520%2520%2520%2520%2520%2520%2520%2520%257B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2F%2FLets%2520assume%2520this%2520works%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520var%2520jupiter%2520%3D%2520new%2520Planet%2520%257B%2520Name%2520%3D%2520%26quot%3BJupiter%26quot%3B%2520%257D%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520context.Planets.Add(jupiter)%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520context.SaveChanges()%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2F%2FAnd%2520then%2520this%2520will%2520throw%2520an%2520exception%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520var%2520neptune%2520%3D%2520new%2520Planet%2520%257B%2520Name%2520%3D%2520%26quot%3BNeptune%26quot%3B%2520%257D%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520context.Planets.Add(neptune)%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520context.SaveChanges()%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2F%2FWithout%2520this%2520line%2C%2520no%2520changes%2520will%2520get%2520applied%2520to%2520the%2520database%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520transaction.Commit()%3B%2520%2520%2520%2520%2520%2520%2520%2520%257D%2520%2520%2520%2520%2520%2520%2520%2520catch%2520(Exception%2520ex)%2520%2520%2520%2520%2520%2520%2520%2520%257B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2F%2FThere%2520is%2520no%2520need%2520to%2520call%2520transaction.Rollback()%2520here%2520as%2520the%2520transaction%2520object%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2F%2Fwill%2520go%2520out%2520of%2520scope%2520and%2520disposing%2520will%2520roll%2520back%2520automatically%2520%2520%2520%2520%2520%2520%2520%2520%257D%2520%2520%2520%2520%257D%257D%253C%2Fcode">
Note that it may be a developers' convention to call transaction.Rollback() explicitly, because it makes the code more self-explanatory. Also, there may be (less well-known) query providers for Entity Framework out there that don't implement Dipsose correctly, which would also require an explicit transaction.Rollback() call.