Disable automatic table creation in Entity Framework

Usually I prefer code first approach which in turn leads to create or update database based on the any change that I do in my entity model classes. This is very straight forward.

But in one of my recent project for and enterprise client they asked not to do any change in database from code as database should be maintained by the DBA team only so I have to disable database creation and upgrade from my code. To do that I simply have to update one line in my code that is Database.SetInitializer.

Usually when we update database from code we do it like below

Database.SetInitializer<MyEntities>(new MyEntitiesSeed());

Here MyEntitiesSeed is an inherited instance of DropCreateDatabaseIfModelChanges which is responsible for Create or Drop of database in case of model change.

For avoiding any change in database from code we can simply update the above statement as shown below:


This will disable any database change Entity Framework can do from application.