gpt4 book ai didi

asp.net-mvc-3 - MVC-Mini-Profiler 错误地显示重复查询

转载 作者:行者123 更新时间:2023-12-04 12:24:32 26 4
gpt4 key购买 nike

我一直在玩 MVC-Mini-Profiler,发现它非常有用。但是,在我跟踪的所有页面上,我都会收到重复查询的报告,如下所示。

但是,我已经在 SQL Server Profiler 中跟踪了查询,毫无疑问它只访问了数据库一次。

我在这里遗漏了一个概念还是我设置错误?我已经搜索了有类似问题的人,但没有运气,所以我怀疑是否存在错误。

Trace

http://localhost:27941/clubs
T+175.2 ms
Reader
13.6 ms
utePageHierarchy Execute System.Collections.Generic.IEnumerable<T>.GetEnumerator GetResults Execute ExecuteStoreCommands
SELECT
[Extent1].[TeamId] AS [TeamId],
[Extent1].[Title] AS [Title],
[Extent1].[TitleShort] AS [TitleShort],
[Extent1].[LogoImageId] AS [LogoImageId],
[Extent1].[Slug] AS [Slug],
(SELECT
COUNT(1) AS [A1]
FROM [dbo].[Athletes] AS [Extent2]
WHERE [Extent1].[TeamId] = [Extent2].[TeamId]) AS [C1]
FROM [dbo].[Teams] AS [Extent1]
WHERE 352 = [Extent1].[CountryId]

http://localhost:27941/clubs
T+175.4 ms
DUPLICATE Reader
13.4 ms
utePageHierarchy Execute System.Collections.Generic.IEnumerable<T>.GetEnumerator GetResults Execute ExecuteStoreCommands
SELECT
[Extent1].[TeamId] AS [TeamId],
[Extent1].[Title] AS [Title],
[Extent1].[TitleShort] AS [TitleShort],
[Extent1].[LogoImageId] AS [LogoImageId],
[Extent1].[Slug] AS [Slug],
(SELECT
COUNT(1) AS [A1]
FROM [dbo].[Athletes] AS [Extent2]
WHERE [Extent1].[TeamId] = [Extent2].[TeamId]) AS [C1]
FROM [dbo].[Teams] AS [Extent1]
WHERE 352 = [Extent1].[CountryId

我使用 EF4 并实现了这样的上下文:
public class BaseController : Controller
{
public ResultsDBEntities _db;

public BaseController()
{
var rootconn = ProfiledDbConnection.Get(GetStoreConnection(ConfigurationManager.ConnectionStrings["ResultsDBEntities"].ConnectionString));
var conn = ProfiledDbConnection.Get(rootconn);
_db = ObjectContextUtils.CreateObjectContext<ResultsDBEntities>(conn);
}

public static DbConnection GetStoreConnection<T>() where T : System.Data.Objects.ObjectContext
{
return GetStoreConnection("name=" + typeof(T).Name);
}

public static DbConnection GetStoreConnection(string entityConnectionString)
{
DbConnection storeConnection;

// Let entity framework do the heavy-lifting to create the connection.
using (var connection = new EntityConnection(entityConnectionString))
{
// Steal the connection that EF created.
storeConnection = connection.StoreConnection;

// Make EF forget about the connection that we stole (HACK!)
connection.GetType().GetField("_storeConnection",
BindingFlags.NonPublic | BindingFlags.Instance).SetValue(connection, null);

// Return our shiny, new connection.
return storeConnection;
}
}
}

最佳答案

我将此报告给 Mini Profiler 团队 (http://code.google.com/p/mvc-mini-profiler/issues/detail?id=62&can=1),他们今天发布了一个补丁,似乎可以修复问题。

我想这将包含在下一个版本中。希望有帮助:)

关于asp.net-mvc-3 - MVC-Mini-Profiler 错误地显示重复查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6585270/

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