From 75782d85ea046f059ce4756c410bc385b0dc7288 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 31 Oct 2024 15:31:01 +0100 Subject: [PATCH] Reduce section on temporal table migrations into a single bullet --- .../core/what-is-new/ef-core-9.0/whatsnew.md | 119 +----------------- 1 file changed, 4 insertions(+), 115 deletions(-) diff --git a/entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md index 334ae272b3..3b4dfc5c2d 100644 --- a/entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md @@ -1067,121 +1067,6 @@ The above were only some of the more important query improvements in EF9; see [t ## Migrations - - -### Improved temporal table migrations - -The migration created when changing an existing table into a temporal table has been reduced in size for EF9. For example, in EF8 making a single existing table a temporal table results in the following migration: - -```csharp -protected override void Up(MigrationBuilder migrationBuilder) -{ - migrationBuilder.AlterTable( - name: "Blogs") - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); - - migrationBuilder.AlterColumn( - name: "SiteUri", - table: "Blogs", - type: "nvarchar(max)", - nullable: false, - oldClrType: typeof(string), - oldType: "nvarchar(max)") - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); - - migrationBuilder.AlterColumn( - name: "Name", - table: "Blogs", - type: "nvarchar(max)", - nullable: false, - oldClrType: typeof(string), - oldType: "nvarchar(max)") - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); - - migrationBuilder.AlterColumn( - name: "Id", - table: "Blogs", - type: "int", - nullable: false, - oldClrType: typeof(int), - oldType: "int") - .Annotation("SqlServer:Identity", "1, 1") - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart") - .OldAnnotation("SqlServer:Identity", "1, 1"); - - migrationBuilder.AddColumn( - name: "PeriodEnd", - table: "Blogs", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)) - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); - - migrationBuilder.AddColumn( - name: "PeriodStart", - table: "Blogs", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)) - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); -} -``` - -In EF9, the same operation now results in a much smaller migration: - -```csharp -protected override void Up(MigrationBuilder migrationBuilder) -{ - migrationBuilder.AlterTable( - name: "Blogs") - .Annotation("SqlServer:IsTemporal", true) - .Annotation("SqlServer:TemporalHistoryTableName", "BlogsHistory") - .Annotation("SqlServer:TemporalHistoryTableSchema", null) - .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd") - .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart"); - - migrationBuilder.AddColumn( - name: "PeriodEnd", - table: "Blogs", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)) - .Annotation("SqlServer:TemporalIsPeriodEndColumn", true); - - migrationBuilder.AddColumn( - name: "PeriodStart", - table: "Blogs", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)) - .Annotation("SqlServer:TemporalIsPeriodStartColumn", true); -} -``` - ### Protection against concurrent migrations @@ -1210,6 +1095,10 @@ Here is an example of how these methods can be used: More information can be found [here](/ef/core/modeling/data-seeding#use-seeding-method). +### Other migration improvements + +* When changing an existing table into a SQL Server temporal table, the migration code size has been significantly reduced. + ## Model building