How to setup miniprofiler for database-first entity framework?


#1

I am trying to use mvc-mini-profiler for db-first EF, but it is not working properly.
(note that I’m using objectcontext, not dbcontext)

Here is the list of stackoverflows I’ve tried:

  • Setup of mvc-mini-profiler for EF-db- first
  • How to get MVC-mini-profiler working on EF 4.1 Database First

versions:

  • Entity Framework: 4.3.1
  • MiniProfiler: 2.0.2
  • MiniProfiler.ef: 2.0.3

This is how I setup miniprofiler:

I’ve added the following stuff in Global.asax

protected void Application_BeginRequest(
{
     MiniProfiler.Start();   
}

protected void Application_EndRequest()
{
     MiniProfiler.Stop();
}

protected void Application_Start()
{
    ...

    MiniProfilerEF.Initialize_EF42();
}

Then configure an objectcontext,

var entityConnection = new EntityConnection(ConnectionString);
var profiledDbConnection = new EFProfiledDbConnection(entityConnection, MiniProfiler.Current);
var context = profiledDbConnection.CreateObjectContext<MyContext>();
var list = context.MyEntities.ToList();

If I execute this, the following exception occurs when running “context.MyEntities.ToList()”

[System.Data.EntityCommandCompliationException]

the message in the inner exception says: EntityClient cannot be used to create a command definition from a store command tree.

Have I configured wrong? Any help?

thanks,