加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 04:09:44 所属栏目:asp.Net 来源:网络整理
导读:我一直在玩MVC-Mini-Profiler,发现它非常有用.但是,在我追踪的所有页面上,我都会收到重复查询的报告,如下所示. 但是,我已经在SQL Server Profiler中跟踪了查询,毫无疑问它只能访问DB一次. 我在这里错过了一个概念还是我设置错了?对于有类似问题的人,我一直
我一直在玩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=62u0026amp;can=1),他们今天发布了一个补丁解决问题.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读