I assume that MyModel
is the context created by the Entity Framework Designer, right? An EntityConnection can be created from a DbConnection in combination with a MetadataWorkspace
. I also assume that the EF Designer has added a connectionstring-property to your app/web.config which contains something like this:
metadata=res://*/Content.MyModel.csdl|res://*/Content.MyModel.ssdl|res://*/Content.MyModel.msl;
These are the 3 components that make up your MetadataWorkspace. To create your an EntityConnection from these information you must provide each file within an array:
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);
I haven't tested this with the MvcMiniProfiler (first installed it right now), but there might be some issues, if the profiled-connection doesn't exactly behave like the original MySqlConnection, give a try otherwise a will try to create your setup.