一:數(shù)據(jù)庫不存在時重新創(chuàng)建數(shù)據(jù)庫
Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testContext>());
?
二:每次啟動應(yīng)用程序時創(chuàng)建數(shù)據(jù)庫
?
Database.SetInitializer<testContext>(new DropCreateDatabaseAlways<testContext>());
三:模型更改時重新創(chuàng)建數(shù)據(jù)庫
?
Database.SetInitializer<testContext>(new DropCreateDatabaseIfModelChanges<testContext>());
四:從不創(chuàng)建數(shù)據(jù)庫
?
Database.SetInitializer<testContext>(null);
本文摘自 :https://www.cnblogs.com/