ASP.NET vNext MVC and Entity Framework issues

I am trying to create a small ASP.NET vNext WebAPI + AngularJS + Entity Framework project. But obviously a lot has changed in EF7, so I am experiencing the following issues:

I modified project.json as follows:

 "dependencies": { "Microsoft.AspNet.Server.IIS": "1.0.0-beta1", "EntityFramework": "7.0.0-beta1", "EntityFramework.SqlServer": "7.0.0-beta1", "EntityFramework.Commands": "7.0.0-beta1", "Microsoft.AspNet.Mvc": "6.0.0-beta1", "Microsoft.AspNet.Diagnostics": "1.0.0-beta1", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta1" 

In my DataContext class, I am trying to do the following:

 using System; using Project1.Models; using Microsoft.Data.Entity; namespace Project1.DataAccess { public class DataContext { public DbSet<Website> Websites { get; set; } public DataContext() { Microsoft.Data.Entity.Infrastructure.Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataContext>()); //Database.SetInitializer(new DropCreateDatabaseAlways<DataContext>()); } } } 

}

First of all: Why did the System.Data.Entity namespace change to Microsoft.Data.Entity ? I can't find anything about this change in any Microsoft MSDN article!

Second: the whole Database.SetInitializer no longer works. He recommends using the Microsoft.Data.Entity.Infrastructure namespace, but this database class does not contain the SetInitializer method.

+5
source share
2 answers

Since EF7 is still in pre-release, you will not yet find documentation for it in MSDN articles; you need to look at the EF7 GitHub Wiki for any information.

As you tried EF7, please keep in mind that this is a very early stage in the development of the new EF code base, and there are many functions that are partially implemented or not yet available.

I believe that SetInitializer is one of those things that were implemented in a completely different way; the team avoids static methods to improve structure verifiability.

Also note that the latest version of EF7 is 7.0.0-beta3 , but the wiki provides information on how to use nightly builds . (Using nightly builds can be rude given the big changes since the VS2015 CTP6 was released.)

+4
source

EF7 is lighter and more modular to support new platforms and non-relational data warehouses. The changes are very fundamental, so some core APIs have changed, including their namespaces.

The new light weight means that behind the scenes something less will happen than in previous versions. Database initializers are deleted, so databases will not be created on demand. Instead, you must control this process yourself using the Database Migrations . For more information: ASP.NET vNext (MVC6) Ground Up # 3 - Entity Framework 7

+4
source

All Articles