将 mvc-mini-profiler 与 EF 4.0 和 Ninject 结合使用
我正在尝试将新的 mvc-mini-profiler 与基于 EF4 的应用程序一起使用,但我不知道如何正确连接到目标数据源。
据我所知。
Func<IMyContainer> createContainer = () =>
{
var profiler = MiniProfiler.Current;
if (profiler != null)
{
var rootConn = // ????
var conn = ProfiledDbConnection.Get(rootConn);
return ObjectContextUtils.CreateObjectContext<MyContainer>(conn);
}
else
{
return new MyContainer();
}
};
kernel.Bind<IMyContainer>().ToMethod(ctx => createContainer()).InRequestScope();
如何在没有容器本身的情况下连接到 EF 容器?我只是新建一个 SqlConnection,只不过连接字符串包含在所有 EF 垃圾中。
I'm trying to use the new mvc-mini-profiler with my EF4 based app, but I have no idea how to properly get a connection to my destination datasource.
Here's as far as I have gotten.
Func<IMyContainer> createContainer = () =>
{
var profiler = MiniProfiler.Current;
if (profiler != null)
{
var rootConn = // ????
var conn = ProfiledDbConnection.Get(rootConn);
return ObjectContextUtils.CreateObjectContext<MyContainer>(conn);
}
else
{
return new MyContainer();
}
};
kernel.Bind<IMyContainer>().ToMethod(ctx => createContainer()).InRequestScope();
How do I get a connection to an EF container, without the contianer itself? I would just new-up a SqlConnection, except that the connection string is wrapped in all of the EF junk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
稍微不那么hacky的方式:
Amendment by John Gietzen:
所有答案的组合应该适用于实体框架支持的任何后备存储。
Slightly less hacky way:
Amendment by John Gietzen:
This combination of all of the answers should work for ANY backing store that Entity Framework supports.
这是一个性能稍微好一点但稍微黑客一点的获取商店连接的解决方案。
Here is a slightly better performing, but slightly hackier solution to getting the store connection.
您必须直接初始化连接,如下所示:
You have to initialize the connection directly, as such: