forked from SyleKu/ProStudCreator
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
If we changed from LINQ-to-SQL to EF Core, schema updates would become a whole lot easier. During application startup, we can run dbContext.Database.Migrate();, and the database schema will be at the current level. EF Core supports automatic up- and down-grading of schemas.
Here's how it would work
- Rip out LINQ-to-SQL (.dbml), etc.
- Use automated tooling to create a "EF Code First" model once, for example with https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools
- Run
dotnet ef migrations add InitialCreate - Make sure that the application executes
dbContext.Database.Migrate();at startup - Enable lazy loading (https://learn.microsoft.com/en-us/ef/core/querying/related-data/lazy)
When we want to change the schema
- Edit the C# models
- Run
dotnet ef migrations add AddAwesomeNewFieldToProjectTable - Review the generated migration code to make sure it doesn't accidentally delete important data
Here's some documentation: https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli
Notes
- Modern EF Core versions don't support .NET Framework 4.8 anymore (which we're using here). We should use EF Core 3.1 instead.
- There's a difference between Entity Framework (EF), and Entity Framework Core. EF Core is a complete re-write of EF, and much newer.
- This migration will be helpful if we eventually move this application to a modern .NET version.
Reactions are currently unavailable