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

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – MVC-Mini-Profiler错误地显示重复的查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在玩MVC-Mini-Profiler,发现它非常有用.但是,在我追踪的所有页面上,我都会收到重复查询的报告,如下所示.

但是,我已经在sql Server Profiler中跟踪了查询,毫无疑问它只能访问DB一次.

我在这里错过了一个概念还是我设置错了?对于有类似问题的人,我一直在搜索高低,没有运气,所以我怀疑是否存在错误.

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],(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\u0026amp;can=1),他们今天发布了一个补丁解决问题.

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

原文链接:https://www.f2er.com/aspnet/247397.html

猜你在找的asp.Net相关文章