我首先使用代码运行带有实体框架核心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核心迁移验证查询
发布评论