1
Answer

Call dbfirst migration script through in Entity framework.

Hi,
 
I have developed application based on Asp.net MVC 5 .where I am using entity framework db first approach for my all database creation.
 
I am building functionality that whenever I publish my application in production environment with empty db it should create db schema when application run for first time.
 
My current issue is I have my db first migration script with all schemas require in migration folder. If I want to run migration I have to fire command something like 'Update-Database'. But my motive is to run this command or achieve db schema creation through my code on app start event.
 
Is there any way I can achieve this functionality? Require your help and suggestion.
 
Thanks,
Answers (1)
1
Manav Pandya
NA 7.1k 24.1k 7y
Hello
 
First of all "migration" is related to code-first , not DB First 
 
There is no migration needed for DB First approach .
 
For code first migration : you should write update-database if your DB have pending changes
To enable migration - automatically write following snippet in configuration.cs file: 
  1. AutomaticMigrationsEnabled = true;    
  2. AutomaticMigrationDataLossAllowed = false;     
Thanks