Defining Code First EF Core Model
Learn about Code-First development in EF Core, where we define our model first, and EF Core generates a matching database.
Implementing Code-First development in EF Core
Sometimes, we will not have an existing database. Instead, we define the EF Core model as Code First, and then EF Core can generate a matching database using create and drop APIs.
Note: The create and drop APIs should only be used during development. Once we release the app, we do not want it to delete a production database.
Example
For example, we might need to create an application for managing students and courses for an academy. One student can sign up to attend multiple courses. One course can be attended by multiple students. This is an example of a many-to-many relationship between students and courses.
Modeling the example
Let’s model this example:
Step 1: Use your preferred code editor to add a new “Console App or console project” named CoursesAndStudents
to the Chapter10
solution or workspace.
In Visual Studio 2022, set the startup project for the solution ...