开发者

MVC Mini Profiler with Entity Framework: How to Get Connection

I would like to use MVC Mini Profiler for Entity Framework Connection. The way I did it is like this:

public static XXXXX.DAL.BO.XXXXXEntities GetEntityConnection()
    {
        var conn = ProfiledDbConnection.Get(new EntityConnection(ConfigurationManager.ConnectionStrings["XXXXXEntities"].ConnectionString));
        return ObjectContextUtils.CreateObjectContext<XXXXX.DAL.BO.XXXXXEntities>(conn);
    }

So the following line is to get the Context for the rest of the code:

XXXXX.DAL.BO.XXXXXEntities ctx = GetEnti开发者_StackOverflow社区tyConnection();

When I attempted to view this site on a browser, however, the WebDev.WebServer40.exe crashed.

Does anyone have any idea why?

Thanks heaps.

P.S. Previously it was

XXXXX.DAL.BO.XXXXXEntities ctx = new XXXXX.DAL.BO.XXXXXEntities();

and it worked fine.


If you are able to use the v3.0.10 nuget for EF6, then all you need to do to hook up Entity Framework is

protected void Application_Start()
{
    MiniProfilerEF6.Initialize();
}

Using EF 5 or earlier (with the corresponding nuget package) would require you to generate an EFProfiledDbConnection as Anirudh wrote in his answer:

var conn =  new EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
return ObjectContextUtils.CreateObjectContext<MyModel>(conn);


try initialising your connection to :

connection = new EFProfiledDbConnection( new EntityConnection(ConfigurationManager.ConnectionStrings["XXXXXEntities"].ConnectionString),
                        MiniProfiler.Current);

works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜