From 89828dd9bc1fccc83e68f2f3f275a09e1ae576cb Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 20 Aug 2021 21:01:20 +0200 Subject: [PATCH] Disable nullability in migrations (#25626) Closes #25624 --- .../Migrations/Design/CSharpMigrationsGenerator.cs | 12 ++++++++++++ .../Design/CSharpMigrationsGeneratorTest.cs | 6 ++++++ .../Migrations/ModelSnapshotSqlServerTest.cs | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index 1431aea4390..7f9350cbb84 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -84,6 +84,10 @@ public override string GenerateMigration( .AppendLine(";"); } + builder + .AppendLine() + .AppendLine("#nullable disable"); + if (!string.IsNullOrEmpty(migrationNamespace)) { builder @@ -184,6 +188,10 @@ public override string GenerateMetadata( .AppendLine(";"); } + builder + .AppendLine() + .AppendLine("#nullable disable"); + if (!string.IsNullOrEmpty(migrationNamespace)) { builder @@ -276,6 +284,10 @@ public override string GenerateSnapshot( .AppendLine(";"); } + builder + .AppendLine() + .AppendLine("#nullable disable"); + if (!string.IsNullOrEmpty(modelSnapshotNamespace)) { builder diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs index 11e66b16cad..bcd377ce3ac 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs @@ -512,6 +512,8 @@ public void Migrations_compile() using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; +#nullable disable + namespace MyNamespace { public partial class MyMigration : Migration @@ -578,6 +580,8 @@ protected override void Down(MigrationBuilder migrationBuilder) using Microsoft.EntityFrameworkCore.Migrations.Design; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable disable + namespace MyNamespace { [DbContext(typeof(CSharpMigrationsGeneratorTest.MyContext))] @@ -708,6 +712,8 @@ public void Snapshots_compile() using Microsoft.EntityFrameworkCore.Migrations.Design; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable disable + namespace MyNamespace { [DbContext(typeof(CSharpMigrationsGeneratorTest.MyContext))] diff --git a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs index 0df68a0fb97..687d5724439 100644 --- a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs +++ b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs @@ -2582,6 +2582,8 @@ public virtual void Owned_types_can_be_mapped_to_view() using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable disable + namespace RootNamespace { [DbContext(typeof(DbContext))] @@ -2665,6 +2667,8 @@ public virtual void Snapshot_with_OwnedNavigationBuilder_HasCheckConstraint_comp using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable disable + namespace RootNamespace { [DbContext(typeof(DbContext))] @@ -5292,6 +5296,8 @@ static List getAllProperties(IModel model) using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using NetTopologySuite.Geometries; +#nullable disable + namespace RootNamespace { [DbContext(typeof(DbContext))] @@ -5674,6 +5680,8 @@ protected virtual string AddBoilerPlate(string code, bool usingSystem = false) using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable disable + namespace RootNamespace {{ [DbContext(typeof(DbContext))]