我有我的解決方案2個項目,你可以看到:代碼首先在EF不創建數據庫
我想先用代碼來創建我的數據庫,所以我的代碼來創建模型是:
namespace CMSDataLayer
{
public class CMSDataContext : DbContext
{
public CMSDataContext()
: base("DefaultConnection")
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
Database.SetInitializer(
new MigrateDatabaseToLatestVersion<CMSDataContext, CMSMigrationsConfiguration>()
);
}
public DbSet<table1> Topics { get; set; }
}
}
和
public class CMSMigrationsConfiguration : DbMigrationsConfiguration<CMSDataContext>
{
public CMSMigrationsConfiguration()
{
this.AutomaticMigrationDataLossAllowed = true;
this.AutomaticMigrationsEnabled = true;
}
}
}
我添加的連接字符串MVC p roject webconfig
運行數據庫後沒有創建。我在CMSDataContext類中放置了一個斷點,但斷點從未調用過。爲什麼?
我很早就在EF代碼中。
最好的問候
我永遠不會使用這些標誌'this.AutomaticMigrationDataLossAllowed = true; this.AutomaticMigrationsEnabled = true;' –
我將CMSdatalayer添加到我的mvc項目 –
@EricJ。爲什麼親愛的朋友? –