禁用EF核心迁移验证查询 [英] Disable EF Core Migration verification query

查看:66
本文介绍了禁用EF核心迁移验证查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用代码运行带有实体框架核心2.1.4的asp.net核心2.1.4 Web应用程序.迁移和种子是在应用程序启动时完成的.

I'm running an asp.net core 2.1.4 web application with entity framework core 2.1.4 using code first. The migration and seed are done on application startup.

我注意到几个EF查询正在检查每个呼叫的迁移历史记录:

I've noticed a couple of EF queries checking for checking the migration history on every call:

Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]');

Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]');

Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT [MigrationId], [ProductVersion] FROM [__EFMigrationsHistory] ORDER BY [MigrationId];

No migrations were applied. The database is already up to date.

我不想在每次通话时都检查数据库.因此,我更改了ServiceLifetime.Singleton.但我仍然在每次通话中看到此验证查询.

I don't want to check the database on every call. So I changed the ServiceLifetime.Singleton. But still I see this verification queries on every call.

services.AddDbContext<ApplicationDbContext>(options =>
{
    options.UseSqlServer(dbConnectionString,
        builder => builder.MigrationsAssembly(migrationsAssembly));
}, ServiceLifetime.Singleton, ServiceLifetime.Singleton);

关于EF6,存在类似的问题:如何禁用每次DbContext初始化期间的迁移验证

There is a similar question on EF6: How to disable Migration Verification during every DbContext initialization

NullDatabaseInitializer在EF核心中不存在.

The NullDatabaseInitializer doesn't exist in EF core.

建议做什么?这是正常行为吗?

What is recommended to do? Is this normal behavior?

推荐答案

我发现了问题: https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/778

使用真实的" SQL事件探查器后,我发现它正在按预期工作,就像@ Ivan-Stoev所说的那样.我这边的请求以某种方式使用了相同的operation_id.因此,应用程序洞察力向我显示的痕迹和依赖关系实际上并不相关.

After using a "real" SQL profiler I found out it was working as expected like @Ivan-Stoev said. The requests on my side were somehow using the same operation_id. So the traces and dependencies that where shown to me by application insights where actually not related.

我通过删除默认的AI DependecyTracking修复了该问题.

I fixed it by removing the default DependecyTracking of AI.

private void RemoveDefaultAiDependencyTracking(IServiceCollection services)
{
    var serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ImplementationType == typeof(DependencyTrackingTelemetryModule));
    services.Remove(serviceDescriptor);
}

感谢您的宝贵时间,很抱歉浪费您的时间.

Thanks for you time and sorry for wasting it..

这篇关于禁用EF核心迁移验证查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆