diff --git a/entity-framework/core/managing-schemas/migrations/managing.md b/entity-framework/core/managing-schemas/migrations/managing.md index 07455abe07..c8bfa59cb1 100644 --- a/entity-framework/core/managing-schemas/migrations/managing.md +++ b/entity-framework/core/managing-schemas/migrations/managing.md @@ -196,7 +196,10 @@ This can be used to manage any aspect of your database, including: * Triggers * Views -In most cases, EF Core will automatically wrap each migration in its own transaction when applying migrations. Unfortunately, some migrations 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`. +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`. + +> [!NOTE] +> In EF Core 9, EF Core spans all pending migrations with a single transaction by default (this was reverted in EF Core 10). See [the breaking change note](xref:core/what-is-new/ef-core-9.0/breaking-changes#migrations-single-transaction) for details. ## Remove a migration diff --git a/entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md index 1e31fc741a..28032a1a6b 100644 --- a/entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md @@ -36,6 +36,7 @@ EF Core 9 targets .NET 8. This means that existing applications that target .NET | [EF tools no longer support .NET Framework projects](#ef-tools-no-netfx) | Low | | [`EF.Constant()` and `EF.Parameter()` no longer work inside compiled queries](#ef-constant-compiled) | Low | | [Some `NoTrackingWithIdentityResolution` queries are now prohibited for JSON collections](#no-tracking-json) | Low | +| [All pending migrations are applied in a single transaction](#migrations-single-transaction) | Low | ## High-impact changes @@ -450,6 +451,28 @@ var blogs = await context.Blogs .ToListAsync(); ``` + + +### All pending migrations are applied in a single transaction + +[Tracking Issue #34439](https://github.com/dotnet/efcore/issues/34439) + +#### Old behavior + +Previously, EF Core would (by default) wrap each migration in its own transaction when applying migrations. + +#### New behavior + +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. + +#### Why + +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. + +#### Mitigations + +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. + ## Azure Cosmos DB breaking changes 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.