Owned entity on genericly typed entity generates unwanted steps in new migrations #32763
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
Servicing-approved
type-bug
Milestone
After upgrading our code from .NET 6 to .NET 8 we noticed some strange lines showing up in newly generated migration scripts. Even when there are no changes to the model, add-migration creates a migration which wants to drop some non-existent foreign keys and corresponding columns. Upon further inspection this column corresponds to the primary key of an owned entity of an entity whose class is genericly typed.
This is a minimal example that reproduces the problem:
If you run Add-Migration from the EF core tools on this model, the first generated migration is fine. Every migration generated thereafter (even if no changes were made to the code) will contain the following two lines (besides all actual changes):
In the TestContextModelSnapshot.cs we find:
The line containing
appears to be new. It did not appear in snapshots generated with the .NET 6 version of EF core. Since the property name seems to have changed in .NET 8, the column name seems to be added to stay consistent with previous version, even though this shadow property is never persisted to the database. Removing this line before generating a migration will make the migration omit the drop statements, but it does reinsert this line into the snapshot making it necessary to repeat this before every migration thereafter.
System information
EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer 8.0.1
Target framework: .NET 8
Operating system: Windows
IDE: Visual Studio Enterprise 2022 17.8.3
The text was updated successfully, but these errors were encountered: