When is the Seed method called in a EF code first migrations scenario?

前端 未结 2 1229
旧巷少年郎
旧巷少年郎 2021-01-01 13:50

I\'m new in a project and there is this class for the seed data:

 internal sealed class Configuration : DbMigrationsConfiguration
    {
           


        
2条回答
  •  礼貌的吻别
    2021-01-01 14:40

    When it comes to the migrations Seed() method, coming from DbMigrationsConfiguration class, it's called every time when the Update-Database command is executed. Also when user calls it having existing database.

    There is yet another Seed() method - it is a database initializer. It's invoked when database is creating and doesn't handle existing data (while seed from DbMigrationsConfiguration handles them, checking if specified entities exist).

    Good to look up to One Unicorn blog for more information.

提交回复
热议问题