Using EF with an existing database
In this recipe, we will learn how to create a DbContext
file from an existing database.
There are methods to create the DbContext
and DbSet
classes in EF.
One is the database first approach. With this method, EF tooling support covers database tables and the fields in them to create the DbContext
and DbSet
classes.
Another is the code first approach. With this method, developers create the DbContext
and DbSet
classes by hand, and the EF library can use these classes to reach database tables.
When they released EF Core 1.0, Microsoft declared that EF tooling has no more support for covering and creating the DbContext
and DbSet
classes from existing databases.
Getting ready
Using Visual Studio 2015, we will create an ASP.NET MVC 6 project.
How to do it...
We will create a repository:
- First, we have to be sure that we have imported the following dependencies in
project.json
:
- Let's open a
Developer Command Prompt
for Visual Studio 2015. We will type the following command...