The guide for porting from EF6 to EF Core mentions the possibility of migrating by using the existing database and removing the actual migration code from a new initial migration. From my personal attempt at doing this I'm however running into the following issues:
- Table names in EF6 are based on type, in EF Core on DbSet property name
- Primary keys and foreign keys in EF6 include
dbo. in the constraint names (EF6: PK_dbo.Users, EF Core: PK_Users)
- Foreign keys without foreign key property in EF6 generate names with underscore prefixes before the referenced table key column name, in EF Core the additional underscore is not there
- Index names in EF Core include the table or entity name in the name (
IX_TeamMembers_UserId), EF 6 uses the property name only (IX_UserId)
- EF6 might have generated boolean columns as
[bit] NOT NULL DEFAULT 0, EF Core omits the DEFAULT 0 for new tables (initial migration, so all tables are new). The DEFAULT 0 causes a constraint to be generated, which on migration down is removed by EF6 by looking up the constraint in sys.default_constraints, because the name is partially randomized. A new migration in EF Core that would remove the property would probably fail because the constraint is referencing the property
These are definitely not all. I think it's bad advice to tell people to migrate to EF Core like this, it will cause a lot of frustration when continuing development on the project that was migrated. Some of these issues can definitely be remedied using additional configuration in EF Core, which permits generation of a schema that is much closer to the original EF6 schema. However, when someone would remove that configuration to make use of EF Core defaults you'll again run into issues because you can't rename primary keys if a foreign key is referencing the table.
I think the only feasible approach is to ensure the EF Core model matches table names and column names from the EF6 model, creating a new database using EF Core migrations and copying the data (possibly inserting data with keys) from the old (EF6) to the new (EF Core) database.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The guide for porting from EF6 to EF Core mentions the possibility of migrating by using the existing database and removing the actual migration code from a new initial migration. From my personal attempt at doing this I'm however running into the following issues:
dbo.in the constraint names (EF6:PK_dbo.Users, EF Core:PK_Users)IX_TeamMembers_UserId), EF 6 uses the property name only (IX_UserId)[bit] NOT NULL DEFAULT 0, EF Core omits theDEFAULT 0for new tables (initial migration, so all tables are new). TheDEFAULT 0causes a constraint to be generated, which on migration down is removed by EF6 by looking up the constraint insys.default_constraints, because the name is partially randomized. A new migration in EF Core that would remove the property would probably fail because the constraint is referencing the propertyThese are definitely not all. I think it's bad advice to tell people to migrate to EF Core like this, it will cause a lot of frustration when continuing development on the project that was migrated. Some of these issues can definitely be remedied using additional configuration in EF Core, which permits generation of a schema that is much closer to the original EF6 schema. However, when someone would remove that configuration to make use of EF Core defaults you'll again run into issues because you can't rename primary keys if a foreign key is referencing the table.
I think the only feasible approach is to ensure the EF Core model matches table names and column names from the EF6 model, creating a new database using EF Core migrations and copying the data (possibly inserting data with keys) from the old (EF6) to the new (EF Core) database.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.