EDMx versus Migrations

I am a recent graduate at the beginning of my software development career. I enjoy documenting my learnings through my blogs
I first came across EDMx during college when working on a WPF application that required a database. I decided to look back on this assessment I created to see if there was anything I could do differently or add to it to improve it. For my own learning I decided to start this from scratch which meant recreated the database. I ran into some issues during this recreation of an EDMx database which led me to look into Migrations.
EDMx
EDMx is a tool in Visual Studio that allows you to create your database visually with a diagramming tool. This can be helpful when starting out, however this is an outdated method for creating databases as it works with Entity Framework 4.x.
EDMx is a database first approach, this means that you create your database schema first and the models/classes that represent your entities are then created from this schema.
Migrations
Migrations can be used in Visual Studio but it can also be used through the CLI and Visual Studio Code. It is a more modern technique to creating databases that are linked to models/classes. It is supported by Entity Framework Core which is the most up-to-date version of Entity Framework.
Migrations work off of a code first approach, this means that you would create your models/classes first and you database is automatically generated or updated based on your code.
EDMx vs. Migrations
As I stated previously I started with using the EDMx method and I came to realise that this technique did not suit my needs. I found that through mistakes I would not be able to update my database if, for example a property type was incorrect, I would have to drop the table and create a new one. I learnt that this would not be viable in the real world because it would mean a loss of data already stored in the database. and also the models first created would not be updated this is another step.
EDMx is suitable for beginners who do not intend to make changes to their database once complete. However if changes are required due to mistakes, whether this is a typo issue or a change to property or even adding/removing a property, be prepared to delete your database and start from scratch.
Migrations, however allows for evolution of your database because it is working from your code. Therefore if you change your code, there is an update for the database but it will not delete the database or its data. There is more version control with Migrations through its migration files. Migrations can also be used in multiple ways, through the CLI, through Visual Studio Code and through the Packet Manager Console in Visual Studio 2022.
My learning from this experience is to look to see if there are better techniques to the same problem, and also to keep up-to-date with evolving technology.
To learn more about Migrations I followed this tutorial: https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=visual-studio




