首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >迷你分析器不显示任何有关sql查询的统计信息?

迷你分析器不显示任何有关sql查询的统计信息?
EN

Stack Overflow用户
提问于 2021-02-04 16:09:20
回答 1查看 342关注 0票数 2

迷你分析器不显示任何有关sql查询的统计信息。

我根据文档和应用程序的示例进行设置:https://miniprofiler.com/dotnet/HowTo/ProfileEFCore https://github.com/MiniProfiler/dotnet/blob/main/samples/Samples.AspNetCore3/Startup.cs

这是我的Startup.cs

代码语言:javascript
复制
public void ConfigureServices(IServiceCollection services)
{           
    services.AddDbContext<MyDbContext>(options => options.UseNpgsql ("connstring..."));
    services.AddMiniProfiler()
        .AddEntityFramework();          
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseMiniProfiler();
    app.UseRouting();
    app.UseEndpoints(endpoints =>
            {
                ...
            });
}

以及调用sql查询的示例。

代码语言:javascript
复制
            await using (var context = scope.ServiceProvider.GetRequiredService<MyDbContext>())
            {
                var myDatas = context.Datas.AsNoTracking()                    
                    .Where(x => x.StartTime > now );

                foreach (var myData in myDatas)
                {
                ...
                }

在执行此请求后,我使用迷你分析器统计信息检查页面:

代码语言:javascript
复制
https://localhost:port/mini-profiler-resources/results-index
https://localhost:port/mini-profiler-resources/results?id=GUID

只看到这个:

代码语言:javascript
复制
|                               | duration (ms)| with children (ms) | from start (ms)
| https://localhost:port/logins/| 231.9        | 236.5              | +0.0
| MiniProfiler Init             | 4.5          | 4.6                | +0.0
| Get Profiler IDs              | 0.1          | 0.1                | +4.5

我错过了什么?为什么我不能看到有关SQL查询的统计信息?

EN

回答 1

Stack Overflow用户

发布于 2021-02-05 09:06:36

弄明白了。有必要通过引用迷你分析器来结束对数据库的调用。

本文中的示例代码:https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/

代码语言:javascript
复制
using (MiniProfiler.Current.Step("PUT method"))
    {
        WeatherForecast weatherForecastById = null;
        using (MiniProfiler.Current.Step("Getting Weather Forecase for the Id"))
        {
            weatherForecastById = GetWeatherForecast(id);
        }

        if (weatherForecastById == null)
        {
            return NotFound();
        }

        if (weatherForecastById.Id != id)
        {
            return BadRequest();
        }
        using (MiniProfiler.Current.Step("Updating the Data"))
        {
            _databaseContext.Entry(weatherForecast).State = EntityState.Modified;
            _databaseContext.SaveChanges();
        }
        return NoContent();
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66049413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档