Database Initializer also removes my Membership tables
-
26-10-2019 - |
Question
I created using aspnet_regsql all the membership tables in my database. however it looks like my initializar is removing the membership tables also
Is it possible that it removes only the tables that belong to the model??
I suppose its because of this line:
public class HRContextInitializer : DropCreateDatabaseAlways<HRContext>
{
Solution
Yes thats right. You choose the "DropCreateDatabaseAlways" initialization strategy. You can change to "DropCreateDatabaseIfModelChanges".
If your model change, EntityFramework try to delete and rebuild the database. Please have a look at EntityFrameork.Migrations to migrate changes without rebuilding the whole database.
Scott Hanselman demos this cool new feature at his blog.
http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx
And Scott Guthries Blog Post about EntityFramework CodeFirst