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