必须采取哪些步骤来强制Visual Studio和Entity Framework删除当前使用的数据库,然后根据ASP的模型目录中的类从头开始生成它。 NET MVC 5项目?
编辑:如果有必要,我会重复:从头开始。
EDIT2:我的Global.asax
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using WebApplication2.Migrations;
using WebApplication2.Models;
namespace WebApplication2 {
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start() {
Database.SetInitializer(new MigrateDatabaseToLatestVersion<PersonContext, Configuration>());
Database.SetInitializer(new DropCreateDatabaseAlways<PersonContext>());
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
WebConfig的一部分
<entityFramework>
<contexts>
<context type="WebApplication2.Models.PersonContext, WebApplication2">
<databaseInitializer type="WebApplication2.Models.PersonInitializer, WebApplication2" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>