Tag Archives: dnx ef

Code First Migrations Entity Framework 7

Create Initial Code First Migration

In order to do Code First Migrations, you first have to set up the command dnx ef. Code first means, that you first do database model changes in the Entity Framework database classes and then apply the changes to the actual database. Please read the 2 previous blog entries about ASP .NET 5 on how to set up the dnx command line tool.

To be more specific, the examples in this article were done using Entity Framework 7 RC1. If you execute dnx ef in your ASP .NET project folder, you will get the following output.

Continue reading

Entity Framework 7 Scaffold DbContext from Existing Database

In previous to 7 versions of the Entity Framework all Entity Framework related commands could be executed within Visual Studio. Now you have to use the new ASP .NET 5 dnx command instead.

DbContext Model Migration from Entity Framework 6

In order to migrate my model from Entity Framework 6 to Entity Framework 7, I did not want to manually adjust my old DbContext for Entity Framework 7. Instead I used scaffolding from my existing database to create a completely new model. This minimizes the risk of introducing errors in the new model. After I generated the model, I deleted the previous Migration History table in the database. This might not be suitable for everyone, but I wanted to make a clean cut after transitioning to EF 7.

Scaffold DbContext

In order to scaffold a DBContext from an existing database, you first have to set up dnx ef. If you have not done so already, please read the 2 previous blog entries about ASP .NET 5.

To be more specific, the examples in this article were done using Entity Framework 7 RC1. If you execute dnx ef in your ASP .NET project folder, you will get the following output.

Continue reading

ASP .NET 5 with Entity Framework 7

Adding Entity Framework 7 Packages to ASP .NET Project

Older versions of the Entity Framework need a full .NET runtime in order to work. If at some point you want to use the new .NET 5 Core e.g. to run your application on Linux etc., you should use Entity Framework 7.

project.json:

A few comments regarding my project dependency setup. Of course, first of all you have to add the Entity Framework libraries as dependencies.

Continue reading