Menu ▼



Posted By :
avatarmrkraju
Total Views : 2028

In Entity Framework avoid creating database if not exist when db instance created.

In entity framework code first approach, while creating the instance of database context it will automatically create the database. To avoid creation of database simple add the below one line code in Global.asax.cs Application_Start() event.


Example:
protected void Application_Start()
{
    System.Data.Entity.Database.SetInitializer<Models.SampleModeEntities>(null);
}


In the above example Models.SampleModeEntities is dbcontext name, change the value with your model dbcontext name.






comments powered by Disqus


Search dotnetlearners.com