Where should I put Database.EnsureCreated?

前端 未结 3 704
终归单人心
终归单人心 2021-01-11 18:50

I have an Entity Framework Core + ASP.NET Core application and when my application starts up I want to ensure that the database is created, and eventually (once I have migra

3条回答
  •  执笔经年
    2021-01-11 19:52

    I think zmbq's suggestion is a correct one and there is a way to ensure that migrations are run along with the deployment, so that binaries and database changes are in sync, using Visual Studio's Publish functionality.

    When publishing against an IIS instance, one can specify target database connection string to use to also run required migrations:

    This will ensure that changes are applied only when needed (not every time application starts) and that application runs using the least required database rights (i.e. database writer, reader etc.) as opposed to rights to alter tables, create indexes etc.

提交回复
热议问题