Reputation: 17264
I have an existing database. To get rid of the 'context has changed since the database was created' exception that occurs with an existing database, I call the following in the Application_Start() of Global.asax.cs as is recommended in what I have read:
Database.SetInitializer<SomeEntities>( null );
The problem is that I need to add a line to Application_Start for each existing entity which has a few problems: -
Ideally, I would like to call this in the constructor of the Entities class (derived from DBContext). I tried the following but it did not work:
Database.SetInitializer(false);
So, my question is, what is the best way to set the initializer inside the Entities class (i.e. class derived from DBContext) rather than in Application_Start. Perhaps a static constructor in the Entities class that calls Database.SetInitializer?
If Database.SetInitializer(false) in the constructor is the correct approach, then I will persevere with it and see where I am going wrong.
Upvotes: 0
Views: 150