Add-Migration generate migration with missing "using" statement when a property is an enum defined in another namespace and using a conversion. #32552
Labels
area-migrations
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
If your model has a property of type enum and that enum is defined in another namespace than your model. When generating a migration, by default the snapshot and migration.designer.cs file will use "int" as the variable type and it works.
But when you add a
HasConversion()
statement (even if empty), the generated snapshot and designer.cs files of the migration will use the enum type. Like so:This results in a project that does not build, because the generated migration files are missing the "using" statement of the enumeration namespace on top of their files.
Include your code
Full reproducible project (just replace the connection string and table name):
Include verbose output
Build afterward:
Include provider and version information
EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11 x64
IDE: Visual Studio 2022 17.9
The text was updated successfully, but these errors were encountered: