3

EntityFrameworkConnectionにMVCMiniProfilerを使用したいと思います。私がそれをした方法はこのようなものです:

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);
    }

したがって、次の行は、残りのコードのコンテキストを取得するためのものです。

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

しかし、このサイトをブラウザで表示しようとすると、WebDev.WebServer40.exeがクラッシュしました。

誰かがその理由を知っていますか?

ヒープに感謝します。

PS以前は

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

そしてそれはうまくいきました。

4

2 に答える 2

1

EF6 に v3.0.10 nuget を使用できる場合は、Entity Framework を接続するために必要なことは次のとおりです。

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

EF 5 以前 (対応する nuget パッケージを使用) を使用するにはEFProfiledDbConnection、Anirudh が回答で書いたように を生成する必要があります。

var conn =  new EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
return ObjectContextUtils.CreateObjectContext<MyModel>(conn);
于 2014-05-07T06:00:01.603 に答える
0

への接続を初期化してみてください:

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

私のために働きます。

于 2013-12-17T09:29:15.957 に答える