Can we run sql script using code first migrations?
I am new to code first and if I want to save my changes to a SQL script file before update-database command of migration, is it possible?
If possible then please provide steps to get it done. Also if script is generated then is it possible that I can run that script using migration?
First you need to create a migration.
Then in the generated migration file you can write your SQL.
// PLAIN SQL Sql("UPDATE dbo.Table SET Created = GETDATE()"); // FROM FILE var sqlFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Custom.sql"); Sql(File.ReadAllText(sqlFile));
Then you run