1
我覺得我錯過了一些非常簡單的東西,我將MVC Miniprofiler集成到我的項目中,但我找不到用正確連接實例化我的上下文的方式,因爲它不是EF Code First,我的模型繼承自ObjectContext,這裏是我的代碼mvc miniprofiler使用DbConnection和實體框架EntityConnection
如何解決這個問題?
我覺得我錯過了一些非常簡單的東西,我將MVC Miniprofiler集成到我的項目中,但我找不到用正確連接實例化我的上下文的方式,因爲它不是EF Code First,我的模型繼承自ObjectContext,這裏是我的代碼mvc miniprofiler使用DbConnection和實體框架EntityConnection
如何解決這個問題?
我假設MyModel
是由實體框架設計器創建的上下文,對吧?可以從DbConnection與MetadataWorkspace
組合創建一個EntityConnection。我還假設EF設計又增添了ConnectionString的屬性到您的應用程序/ web.config中包含這樣的事情:
metadata=res://*/Content.MyModel.csdl|res://*/Content.MyModel.ssdl|res://*/Content.MyModel.msl;
這些都是3個組件,使您的MetadataWorkspace。從這些信息創建一個EntityConnection必須在陣列中提供的每個文件:
string[] paths =
{
// "res://" refers to a embedded resource within your DLL, this is automatically done if
// you've used the EF designer.
"res://*/Content.MyModel.csdl",
"res://*/Content.MyModel.ssdl",
"res://*/Content.MyModel.msl"
};
Assembly[] assembliesToConsider = new Assembly[]
{
typeof(MyModel).Assembly
};
System.Data.Metadata.Edm.MetadataWorkspace workspace = new System.Data.Metadata.Edm.MetadataWorkspace(paths, assembliesToConsider);
EntityConnection connection = new EntityConnection(workspace, profiledConnection);
我還沒有與MvcMiniProfiler(第一次安裝它現在)測試這一點,但如果,可能會有一些問題異形連接並不像原來的MySqlConnection,只是嘗試創建你的設置。
看看這個。 http://stackoverflow.com/questions/6802855/miniprofiler-with-ef-model-first-edmx-model – BZink