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:
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:
This will be executed only once.