我们可以用code首先迁移运行SQL脚本? [英] Can we run sql script using code first migrations?
本文介绍了我们可以用code首先迁移运行SQL脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们能否使用code首先迁移运行SQL脚本?
我是新来的code第一,如果我想救我改变移民更新数据库命令之前SQL脚本文件,这可能吗?
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 posible that i can run that script using migration?
推荐答案
首先,你需要创建一个迁移。
First you need to create a migration.
Add-Migration RunSqlScript
然后在生成的迁移文件,你可以写你的SQL。
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));
然后运行
Update-Database
这篇关于我们可以用code首先迁移运行SQL脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文