Continuing my framework move from .net framework 4.8 to .net 5 (Preview7) I obviously have to take the step moving from a framework Entity Framework to EntityFrameworkCore. A few notes to self regarding the upgrade.
The old context generation doesn’t make sense any more. EF core understandably doesn’t have the design options 4.8 (EF 6.2) had, so what made sense for me was to regenerate the model from database using
Scaffold-DbContext (See e.g. https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx)
This simply worked out of the box, with a new code representation of my database generated in the defined target folder.
As I am dealing with substantial number of tables, some with non-orthodox naming conventions (plural entity names – which I will fix), the generated code varied slightly from my pre-existing entity structure, breaking a lot of code.
Also, the stored procedures were missing. They are now executed using .FromSql or .ExecuteSql (See e.g. https://www.entityframeworktutorial.net/efcore/working-with-stored-procedure-in-ef-core.aspx)
A bit of “back to the future” effect on this one 🙂
Next creating a baseline database migration from my old database was easy. Just followed these guidelines: https://cmatskas.com/ef-core-migrations-with-existing-database-schema-and-data/ …. and voilá!! the first migration was added to my database.
Now it is just a matter of cleaning up a bit in the database, creating a clear migration path from the production database to the target setup for GolfCloudPro.com …. easy right!? :Þ