I'm using ASP.NET Core and Entity Framework Core. I need to create some views and functions programmatically on the app first start. Is there a way to run some custom SQL code while EF is being configurated?
If you are using code first with entity, you can try execute your sql scripts in migration:
First you need to create a migration:
Add-Migration RunMySqlScripts
Then in the generated migration file you can write your SQL:
// PLAIN SQL
Sql("Your sql code here");
// OR FROM FILE
var sqlFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"scripts.sql");
Sql(File.ReadAllText(sqlFile));
Then you run:
Update-Database
This will be executed only once.