我的 Web.config 中有以下内容
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<contexts>
<context type="Models.EVRMDBContext, EVRM">
<databaseInitializer type="System.Data.Entity.DropCreateAlways`1[[Models.EVRMDBContext, EVRM]], EntityFramework" />
</context>
</contexts>
</entityFramework>
但是,一旦我使用/查询我的 DBContext,就不会创建数据库。当我使用 Global.asax 设置 databaseInitializer
System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseAlways<EVRM.Models.EVRMDBContext>());
它确实初始化了数据库。
(将 Entity Framework 5 与 MVC4 一起使用)