gpt4 book ai didi

c# - 如何找到 Entity Framework 对每个传入请求进行的数据库调用次数?

转载 作者:太空狗 更新时间:2023-10-29 21:41:37 26 4
gpt4 key购买 nike

我正在运行一个使用 Entity Framework 4.0 进行数据库交互的 C# 4.0 网站。我想找到导致 Entity Framework 对数据库进行最多调用的页面(因为调用越多,页面可能越慢)。

我会向 Entity Framework 添加某种工具,让实际用户操作网站一段时间,然后分析某种日志以找出哪些页面对数据库产生的调用最多。

是否有某种性能计数器或其他事件可以通过检查来确定 Entity Framework 何时进行了数据库调用?

最佳答案

你可以试试 Entity Framework Profiler (它自己的网站是 here ),虽然这不是免费产品,但它有 30 天的免费试用期。它由 one of the smartest guys around 编写

但是它会标记问题,例如 Select N+1 问题并警告您有关不良做法。

来自简介:

Entity Framework Profiler is a real-time visual debugger allowing a development team to gain valuable insight and perspective into their usage of Entity Framework. The product is architected with input coming from many top industry leaders within the OR/M community. Alerts are presented in a concise code-review manner indicating patterns of misuse by your application. To streamline your efforts to correct the misuse, we provide links to the problematic code section that triggered the alert

再次来自简介(回应评论):

Using the Entity Framework Profiler is easy. First, we need to make the application that we profile aware of the profiler. Then, just start the profiler.

Preparing an application to be profiled

Add a reference to the HibernatingRhinos.Profiler.Appender.dll assembly, located in the downloadable zip. In the application startup (Application_Start in web applications, Program.Main in Windows / console applications, or the App constructor for WPF applications), make the following call:

HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

编辑

似乎您可以初始化分析器以进行离线分析。使用它来初始化它(来自 here ):

HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.InitializeOfflineProfiling(filename);

然后将生成的文件加载到分析器中。

这似乎应该给你你想要的。

关于c# - 如何找到 Entity Framework 对每个传入请求进行的数据库调用次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6265800/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com