How can I get the current database initializer, so I can test that the right one is set before automatic publish?
Edit: I want to create a test case that is testing if a team member forgot to remove a line like this:
Database.SetInitializer<SomeModel>(new DropCreateDatabaseAlways<SomeModel>());
but there is no method or property like Database.GetInitializer().
is there a way to get current database initializer?
I think you are going about this wrong, if you’re relying on developers to remember to commit or not to commit a line.
You should consider decoupling the initialization from the code by setting it in the web.config or app.config. Using web.config transformations or SlowCheetah for app.config, you would have a transformation per configuration, e.g. Debug, Test, Production.
In the Web.Debug.Config, you would then specify which initializer to use for that configuration:
For the other configurations, you would replace the
//entityFramework/contexts/context/databaseInitializer/@typein the above configuration to use another database initializer. This would allow you to use DropCreateDatabaseAlways for Debug, DropCreateDatabaseIfModelChanges for Test and disable initialization for Production.As a test, I tried adding database initialization both in the code and in the .config and the .config takes precedence.