配置类的脚本EF迁移种子 [英] Script EF migration seed from Configuration class
问题描述
我的EF迁移运行良好,但是我还想从我的DbMigrationsConfiguration类中为种子数据生成sql脚本。
当我执行Update-Database时,种子数据运行正常,但是当我执行UpdateDatabase -Script时,我没有获得用于种子插入的sql。我在正常的Update-Database上尝试了-Verbose,但是我也看不到那里的种子语句输出。
I have EF migrations working nicely, but I also want to generate the sql script for the seed data from my DbMigrationsConfiguration class. The seed data runs ok when I do Update-Database, but when I do UpdateDatabase -Script I do not get the sql for the seed inserts. I tried -Verbose on a normal Update-Database but I do not see the seed statements output there either.
这可能吗?
推荐答案
不行。配置类不是迁移本身的一部分-它是执行迁移的基础结构。您的所有迁移都只有一个配置类,并且其 Seed
方法在每次迁移运行后都会执行-您甚至可以使用上下文来播种数据,因此该方法在迁移完成=它不能成为迁移的一部分。仅对迁移类的内容进行脚本化。
No it is not possible. Configuration class is not part of migration itself - it is infrastructure executing the migration. You have single configuration class for all your migrations and its Seed
method is executed after every migration run - you can even use context for seeding data and because of that this method is executed after the migration is completed = it cannot be part of migration. Only content of the migration class is scripted.
这篇关于配置类的脚本EF迁移种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!