diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs index 924c5e76d08..4004f179b0d 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs @@ -86,6 +86,11 @@ public virtual string WriteCode( _sb.AppendLine(); + _sb.AppendLine("// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled."); + _sb.AppendLine("// If you have enabled NRTs for your project, then un-comment the following line:"); + _sb.AppendLine("// #nullable disable"); + _sb.AppendLine(); + _sb.AppendLine($"namespace {finalContextNamespace}"); _sb.AppendLine("{"); diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs index ea981ad0c94..a476ae76a47 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs @@ -75,6 +75,11 @@ public virtual string WriteCode(IEntityType entityType, string @namespace, bool _sb.AppendLine($"using {ns};"); } + _sb.AppendLine(); + _sb.AppendLine("// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled."); + _sb.AppendLine("// If you have enabled NRTs for your project, then un-comment the following line:"); + _sb.AppendLine("// #nullable disable"); + _sb.AppendLine(); _sb.AppendLine($"namespace {@namespace}"); _sb.AppendLine("{"); diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs index 4669887a0aa..ba5ff289c17 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs @@ -26,6 +26,10 @@ public void Empty_model() using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class TestDbContext : DbContext @@ -80,6 +84,10 @@ public void SuppressConnectionStringWarning_works() using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class TestDbContext : DbContext diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs index 44c4f8657d4..401a49889b3 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs @@ -38,6 +38,10 @@ public void Navigation_properties() using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class Post @@ -98,6 +102,10 @@ public void Navigation_property_with_same_type_and_navigation_name() using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class Post @@ -153,6 +161,10 @@ public void Navigation_property_with_same_type_and_property_name() using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class Post @@ -209,6 +221,10 @@ public void Navigation_property_with_same_type_and_other_navigation_name() using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class Post @@ -276,6 +292,10 @@ public void Composite_key() using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled. +// If you have enabled NRTs for your project, then un-comment the following line: +// #nullable disable + namespace TestNamespace { public partial class Post