Entity Framework Code-first default data in database

后端 未结 3 1113
轻奢々
轻奢々 2020-12-12 15:49

How do I handle situations in which I need pre-existing data before the app is started or right after the database is generated. For example, I have a list of countries in w

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 16:22

    You must create custom database initializer derived for example from DropCreateDatabaseIfModelChanges and fill data in overriden Seed method. Then you must use Database.SetInitializer to set your new initializer when application starts. Here is example (from CTP5) used to create custom index in the database.

提交回复
热议问题