From 3bbfc0face6ae428d1918edcd697c32aa7ec752a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Aug 2026 23:04:16 +0000 Subject: [PATCH 1/4] Initial plan From 490636cc6510db90ad0e383d4ff57647fdb728d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Aug 2026 23:07:22 +0000 Subject: [PATCH 2/4] Document automatic transaction behavior Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- entity-framework/core/saving/transactions.md | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/entity-framework/core/saving/transactions.md b/entity-framework/core/saving/transactions.md index 0ba4ef2dd9..2aebefb480 100644 --- a/entity-framework/core/saving/transactions.md +++ b/entity-framework/core/saving/transactions.md @@ -2,7 +2,7 @@ title: Transactions - EF Core description: Managing transactions for atomicity when saving data with Entity Framework Core author: SamMonoRT -ms.date: 9/26/2020 +ms.date: 08/19/2026 uid: core/saving/transactions --- # Using Transactions @@ -18,6 +18,25 @@ By default, if the database provider supports transactions, all changes in a sin For most applications, this default behavior is sufficient. You should only manually control transactions if your application requirements deem it necessary. +## Controlling automatic transactions + +Starting with EF Core 7.0, you can control whether EF automatically creates a transaction when calling `SaveChanges` and no user transaction exists. Set to one of the following values: + +* (default): EF creates a transaction only when needed. For example, most single SQL statements execute in a transaction implicitly, so EF doesn't create an explicit transaction. +* : EF always creates a transaction if no user transaction exists. This may add database roundtrips which degrade performance. +* : EF never creates a transaction automatically. + +For example, configure EF to always create a transaction before calling `SaveChanges`: + +```csharp +context.Database.AutoTransactionBehavior = AutoTransactionBehavior.Always; +``` + +`Always` can be useful if application code relies on transaction creation callbacks being invoked when `SaveChanges` doesn't use a user transaction. + +> [!WARNING] +> Use `AutoTransactionBehavior.Never` with caution. If a failure occurs, the database could be left in an inconsistent state. + ## Controlling transactions You can use the `DbContext.Database` API to begin, commit, and rollback transactions. The following example shows two `SaveChanges` operations and a LINQ query being executed in a single transaction: From 78466e7f8b0c9417cac998f1a08d935fc321d94a Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Wed, 19 Aug 2026 18:05:11 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- entity-framework/core/saving/transactions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entity-framework/core/saving/transactions.md b/entity-framework/core/saving/transactions.md index 2aebefb480..a88b5ae9fe 100644 --- a/entity-framework/core/saving/transactions.md +++ b/entity-framework/core/saving/transactions.md @@ -23,7 +23,7 @@ For most applications, this default behavior is sufficient. You should only manu Starting with EF Core 7.0, you can control whether EF automatically creates a transaction when calling `SaveChanges` and no user transaction exists. Set to one of the following values: * (default): EF creates a transaction only when needed. For example, most single SQL statements execute in a transaction implicitly, so EF doesn't create an explicit transaction. -* : EF always creates a transaction if no user transaction exists. This may add database roundtrips which degrade performance. +* : EF always creates a transaction if no user transaction exists. This may add database roundtrips, which can degrade performance. * : EF never creates a transaction automatically. For example, configure EF to always create a transaction before calling `SaveChanges`: @@ -35,7 +35,7 @@ context.Database.AutoTransactionBehavior = AutoTransactionBehavior.Always; `Always` can be useful if application code relies on transaction creation callbacks being invoked when `SaveChanges` doesn't use a user transaction. > [!WARNING] -> Use `AutoTransactionBehavior.Never` with caution. If a failure occurs, the database could be left in an inconsistent state. +> Use `AutoTransactionBehavior.Never` with caution. If `SaveChanges` needs to execute multiple commands and a failure occurs, earlier commands may have already been committed, leaving partial changes in the database. ## Controlling transactions From 50319e1ddab2d0512209ee39ea804a31e0d8ce5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 01:08:19 +0000 Subject: [PATCH 4/4] Remove obsolete EF Core version qualifier Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- entity-framework/core/saving/transactions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity-framework/core/saving/transactions.md b/entity-framework/core/saving/transactions.md index a88b5ae9fe..c29b948ca5 100644 --- a/entity-framework/core/saving/transactions.md +++ b/entity-framework/core/saving/transactions.md @@ -20,7 +20,7 @@ For most applications, this default behavior is sufficient. You should only manu ## Controlling automatic transactions -Starting with EF Core 7.0, you can control whether EF automatically creates a transaction when calling `SaveChanges` and no user transaction exists. Set to one of the following values: +You can control whether EF automatically creates a transaction when calling `SaveChanges` and no user transaction exists. Set to one of the following values: * (default): EF creates a transaction only when needed. For example, most single SQL statements execute in a transaction implicitly, so EF doesn't create an explicit transaction. * : EF always creates a transaction if no user transaction exists. This may add database roundtrips, which can degrade performance.