0

我制作了一个新的 asp.net mvc4 应用程序,然后安装了 miniprofiler。

然后我只是启用了迁移,添加迁移后我更新了我的数据库。

使用 miniprofiler 我发现有 3 个我不知道的 sql 查询。

我不知道这个初始化发生在哪里

 InitializeDatabase <PerformDatabaseInitialization>b__6 PerformInitializationAction PerformDatabaseInitialization

这是miniprofiler的图片微型轮廓仪

这 3 个 sql 查询是什么?他们来自哪里?

4

1 回答 1

0

This is EF Migrations checking if the database is the same as the EF model. Whenever you run a migration EF stores details of the migration in the [__MigrationHistory] table so it knows if the migrations need to be run.

  • I'm not too sure about first query but I think it's checking if any tables in the db were generated using EF (This is a guess from looking at the stack trace).

  • The second query just returns the number of migrations.

  • The final query gets the latest migration which will then be compared to the EF model. If the model is different to the database an exception will throw saying the database is out of date.

You don't need to worry about these as the migration check is only run once per application startup.

If you want more info on db initialisers take a look at this.

于 2012-09-14T15:46:21.840 回答