Code First EF Core models
Sometimes you will not have an existing database. Instead, you define the EF Core model as Code First, and then EF Core can generate a matching database using create and drop APIs.
Good Practice: The create and drop APIs should only be used during development. Once you release the app, you do not want it to delete a production database!
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.
Let's model this example:
- Use your preferred code editor to add a new console app named
CoursesAndStudents
to theChapter10
solution/workspace. - In Visual Studio, set the startup project for the solution to the current selection.
- In Visual Studio Code, select
CoursesAndStudents
as the active...