dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.79k stars 3.19k forks source link

Scaffolding: Optionally including the `nullable` directive for generated code #33426

Open JohnYoungers opened 7 months ago

JohnYoungers commented 7 months ago

In EFCore5, using the .editorconfig I would mark the scaffolded files as generated_code = true: this ensured the classes wouldn't trigger any analytic or styling issues with the build.

In the past few versions, now that code is scaffolded with <Nullable>enable</Nullable> in mind, my generated_code setting ends up overriding the behavior partially due to this (see the Important section): https://learn.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies#plan-your-migration

I'm not sure if it can be detected automatically, or if we could add a flag to do so, but it would be beneficial if we could include #nullable enable in the generated files for this scenario

JohnYoungers commented 2 days ago

@cincuranet / @roji - does adding that declaration seem feasible?

Without including generated_code = true, we end up triggering several other analytic issues (Collection initialization can be simplified, etc)