Skip to content

Commit 31c757f

Browse files
authored
Concise transaction note in managing.md and low-impact breaking change for EF Core 9 single-transaction migrations
1 parent 8ebfea4 commit 31c757f

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

entity-framework/core/managing-schemas/migrations/managing.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ This can be used to manage any aspect of your database, including:
196196
* Triggers
197197
* Views
198198

199-
In most cases, EF Core will automatically wrap migrations in a transaction when applying migrations. Prior to EF Core 9, each migration was wrapped in its own transaction. Starting with EF Core 9, all pending migrations are applied within a single transaction as part of [migration locking](xref:core/managing-schemas/migrations/applying#migration-locking). Unfortunately, some migration operations cannot be performed within a transaction in some databases; for these cases, you may opt out of the transaction by passing `suppressTransaction: true` to `migrationBuilder.Sql`.
199+
In most cases, EF Core will automatically wrap each migration in its own transaction when applying migrations. Unfortunately, some migration operations cannot be performed within a transaction in some databases; for these cases, you may opt out of the transaction by passing `suppressTransaction: true` to `migrationBuilder.Sql`.
200+
201+
> [!NOTE]
202+
> In EF Core 9, all pending migrations are applied within a single transaction instead. See [the breaking change note](xref:core/what-is-new/ef-core-9.0/breaking-changes#migrations-single-transaction) for details.
200203
201204
## Remove a migration
202205

entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ EF Core 9 targets .NET 8. This means that existing applications that target .NET
3636
| [EF tools no longer support .NET Framework projects](#ef-tools-no-netfx) | Low |
3737
| [`EF.Constant()` and `EF.Parameter()` no longer work inside compiled queries](#ef-constant-compiled) | Low |
3838
| [Some `NoTrackingWithIdentityResolution` queries are now prohibited for JSON collections](#no-tracking-json) | Low |
39+
| [All pending migrations are applied in a single transaction](#migrations-single-transaction) | Low |
3940

4041
## High-impact changes
4142

@@ -450,6 +451,28 @@ var blogs = await context.Blogs
450451
.ToListAsync();
451452
```
452453

454+
<a name="migrations-single-transaction"></a>
455+
456+
### All pending migrations are applied in a single transaction
457+
458+
[Tracking Issue #34439](https://github.com/dotnet/efcore/issues/34439)
459+
460+
#### Old behavior
461+
462+
Previously, each migration was wrapped in its own individual transaction when applying migrations.
463+
464+
#### New behavior
465+
466+
Starting with EF Core 9.0, all pending migrations are applied within a single transaction as part of [migration locking](xref:core/managing-schemas/migrations/applying#migration-locking). If any migration fails, the entire transaction is rolled back. This behavior was reverted in EF Core 10.
467+
468+
#### Why
469+
470+
Applying all migrations in a single transaction ensures the database is either fully up-to-date or left unchanged if an error occurs, avoiding intermediate states.
471+
472+
#### Mitigations
473+
474+
If you need per-migration transaction behavior in EF Core 9, upgrade to EF Core 10, which reverts to wrapping each migration in its own transaction.
475+
453476
## Azure Cosmos DB breaking changes
454477

455478
Extensive work has gone into making the Azure Cosmos DB provider better in 9.0. The changes include a number of high-impact breaking changes; if you are upgrading an existing application, please read the following carefully.

0 commit comments

Comments
 (0)