Force Database Initialization in Code First EF
Continuing on the previous post about using the drop-in Altairis.Web.Security membership provider, I ran into an issue where the database may not be recreated in a timely fashion on a change to the model classes. For example if you add the following property to the User class:
public string FullName { get; set; }
And change the initializer in the ApplicationDB.cs class to drop and create the database on model change:
public class DBInitializer : DropCreateDatabaseIfModelChanges<ApplicationDB>
The problem is if you then access the database by creating a new user in the “Account/Register” controller, the database will not drop and create because the Altairis membership provider uses non-EF (ADO.Net classic) methods of data access. Therefore, the Entity Framework access methods haven’t been touched yet and won’t drop/create the DB until that time.