Thursday, March 26, 2015

Using Entity Framework 7

In this post I'm going to demonstrate about how to use Entity Framework 7 in MVC 6 project. I will use Visual Studio 2015 CTP version.
First create a New Project like below.
I want to build my project from scratch. Therefore create an Empty ASP.net 5 preview project.
There are some visible structural changes in the MVC project. There's a file called Startup.cs, where you can configure your HTTP request pipeline. wwwroot is the web root, where you can put all your static files.
In the references folder, there are two target frameworks which has defined in project.json file.

We need to add references for EntityFramework as nuget packages like below.

Create a folder called Model. Inside that create Student.cs class like below.
Next we need to add DbContext file for this SchoolApp.
Then we need to add EntityFramework migration files. So, open Package Manager Console, and go to SchoolApp folder where the project.json file exists.
We have to execute the following command to add initial migration.
This will give an error due to inability to load the command. Add following command to project.json file.
After the above step, execute following commands.
This will add migration files and also create the database.


No comments:

Post a Comment