禁用EF核心迁移验证查询

编程入门 行业动态 更新时间:2024-10-28 20:28:38
本文介绍了禁用EF核心迁移验证查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm running an asp 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?

推荐答案

我发现了问题: github/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核心迁移验证查询

本文发布于:2023-11-07 04:02:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   EF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!