How do Transactions work in EF Core?
Updated Apr 28, 2026
Short answer
By default, all operations inside a single SaveChanges() call run within a transaction. If any operation fails, the transaction is rolled back.
Deep explanation
You can also manually control transactions when coordinating multiple SaveChanges() calls or executing raw SQL alongside EF operations using Database.BeginTransaction(). Committing makes the changes permanent; rolling back discards them.
Real-world example
Deducting account balance and creating a transaction record. Both must succeed, or neither should happen, maintaining data integrity.
Common mistakes
- Leaving transactions uncommitted or unrolled back, causing severe database deadlocks.
Follow-up questions
- Can EF Core share transactions with ADO.NET connections?