如何强制VS2013从头开始为ASP.NETMVC5项目重建数据库

如何强制VS2013从头开始为ASP.NETMVC5项目重建数据库,.net,database,entity-framework,asp.net-mvc-5,.net,Database,Entity Framework,Asp.net Mvc 5,必须采取哪些步骤来强制VisualStudio和EntityFramework删除当前使用的数据库,然后根据ASP的模型目录中的类从头开始生成它。NETMVC5项目 编辑:如果有必要,我将重复:从头开始 编辑2:我的全球网站asax using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc;

必须采取哪些步骤来强制VisualStudio和EntityFramework删除当前使用的数据库,然后根据ASP的模型目录中的类从头开始生成它。NETMVC5项目

编辑:如果有必要,我将重复:从头开始

编辑2:我的全球网站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);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
使用System.Web.Optimization;
使用System.Web.Routing;
使用WebApplication2.迁移;
使用WebApplication2.Models;
命名空间WebApplication2{
公共类MVC应用程序:System.Web.HttpApplication{
受保护的无效应用程序\u Start(){
SetInitializer(新的MigrateDatabaseToLatestVersion());
SetInitializer(新的DropCreateDatabaseAlways());
RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
网络配置的一部分

<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>


@bradcristie我有
DatbaseInitializer
。我不要求更新数据库。它已经存在了。我询问OP中的具体内容。我知道,但是有一个
DropCreateDatabaseAlways
数据库初始值设定项可以使用。@BradChristie EDIT2。它从来都不起作用我已经试了好几个小时了,这就是我问问题的方式。面对这个问题,我会简单地将数据库放到SQL Server上,重新定义它,然后让VS 2013将模型创建为“ADO实体模型”,我可能不是以新的方式做事情,需要更多的工作,但至少我知道我在做什么,我应该期待看到什么。