Entity Framework Core models

c# entity-framework-core


I have built a ASP.NET Core MVC application that connects to MySQL. I wanted to enhance the solution by adding Entity Framework because it automatically generates entities and models for you. But reading about this new version (EF Core), it looks like you have to create the models in code then run a script to create the database. That seems backwards, what is the benefit if you don't want to create the database at runtime?

I thought Entity Framework was the opposite, you could create the database first, then add connect it in Visual Studio through a nice UI and it would generate everything for you. Why is it reversed now? I would rather maintain the database in MySQL, then fetch / sync the changes in Visual Studio.

8/18/2018 6:12:46 AM

Popular Answer

It is true that Entity Framework Core (for now, at least) only supports the Code First approach, but that only means that the option to generate classes through EDMX files and T4 (normally using the visual designer) is gone.

You have two options for Code First, just as you do in Entity Framework 6:

  1. From scratch. Create your classes as you want, you design your database through the classes.
  2. By reverse-engineering the database to create the classes. You can see here how to do this: Getting Started with EF Core on ASP.NET Core with an Existing Database.

Both options will leave you tied only to your POCOs and you can decide whether you want to use migrations or not.

8/17/2018 11:44:38 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow