7

I have been playing around with MVC-Mini-Profiler, and found it very useful. However, on all pages I trace on, I get reports of duplicate queries, like the one below.

However, I have traced the queries in SQL Server Profiler, and there is not doubt it only hits the DB once.

Am I missing a concept here or have I set it up the wrong way? I have searched high and low for people with similar problems, with no luck, so I doubt there is a bug.

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

I use EF4 and have implemented the context like this:

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;
        }
    }
}
Kjensen
  • 12,447
  • 36
  • 109
  • 171
  • does this happen if you grab the latest nuget? ... can you ensure you do a `var s = MiniProfiler.Current.Step("whatever"))` at the start of your request and dispose it at the end of your request? – Sam Saffron Jul 19 '11 at 08:05
  • I arrived here because I'm experiencing the same issue. No db profiling involved (yet!) - just ajax requests that are only being sent once (Glimpse confirms this) yet appear multiple times in the output. I can see corresponding multiple calls to /mini-profiler-results?id=SOMEGUID where SOMEGUID is sometimes duplicated. In the example I'm looking at right now there are six calls to /mini-profiler-results for four ajax requests, two with duplicate GUIDS, and this corresponds to my six output results from the profiler. Hope that makes sense! – randomsequence Jul 22 '11 at 14:24
  • I'm experiencing this problem with MVC Mini Profiler version 1.9. – solidbeats Dec 01 '11 at 22:45

1 Answers1

5

I reported this to the Mini Profiler team (http://code.google.com/p/mvc-mini-profiler/issues/detail?id=62&can=1) and they've issued a patch today which appears to fix the issue.

I imagine this will be included in the next release. Hope that helps :)

randomsequence
  • 1,338
  • 1
  • 11
  • 14