如何解决Mini-profiler 不显示任何关于 sql 查询的统计信息?
我根据文档和应用程序示例进行设置: https://miniprofiler.com/dotnet/HowTo/ProfileEFCore https://github.com/MiniProfiler/dotnet/blob/main/samples/Samples.AspNetCore3/Startup.cs
这是我的 Startup.cs
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 =>
{
...
});
}
await using (var context = scope.ServiceProvider.GetrequiredService<MyDbContext>())
{
var myDatas = context.Datas.AsNoTracking()
.Where(x => x.StartTime > Now );
foreach (var myData in myDatas)
{
...
}
https://localhost:port/mini-profiler-resources/results-index
https://localhost:port/mini-profiler-resources/results?id=GUID
并且只看到这个:
| | 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
解决方法
想通了。有必要通过引用迷你分析器来包装对数据库的调用。
本文中的示例代码: https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/
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();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。