MVC-迷你分析器配置澄清 [英] mvc-mini-profiler configuration clarification

查看:121
本文介绍了MVC-迷你分析器配置澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

探查安装在我的MVC 3应用程序和它的作品,但我有一个困难时期什么是正确获得EF4分贝部分设置了正确的道路。

The profiler is installed in my MVC 3 app and it works, but what I'm having a hard time with is the correct way to get the EF 4 db portion setup correctly.

从事件探查器的首页

使用一个工厂来回报您的连接:

Use a factory to return your connection:

public static DbConnection GetOpenConnection()
{
    var cnn = CreateRealConnection(); 

    // wrap the connection with a profiling connection that tracks timings 
    return MvcMiniProfiler.Data.ProfiledDbConnection.Get(cnn, MiniProfiler.Current);
}

实体框架

public static MyModel Get()
{
    var conn = ProfiledDbConnection.Get(GetConnection());
    return ObjectContextUtils.CreateObjectContext<MyModel>(conn);
}

好了,所以马上蝙蝠,我想澄清的调用为MyModel获取方法的getConnection()是否应该读GetOpenConnection()?

Ok, so right off the bat I'd like clarification whether the call to GetConnection() of the MyModel Get method should read GetOpenConnection()?

那么,如果它是一个错字,会是什么CreateRealConnection样子?我使用ODP.NET通过提供者模型和我的模型库没有一个裁判Oracle.DataAccess.Client和我preFER继续保持这种方式,如果我能。

Then if it is a typo, what would the CreateRealConnection look like? I am using ODP.NET via the provider model and my Model Library does not have a ref to Oracle.DataAccess.Client and I'd prefer to keep it that way if I can.

此外,在将所有这些code驻留在我的资料库?

Also, where would all this code reside in my repository?

public IQueryable<PRODUCTHEADER> Products
{
    get{ return ctx.PRODUCTHEADERs.AsQueryable(); }
}

感谢您,
斯蒂芬

Thank you, Stephen

推荐答案

我能够从这篇文章拿块<一个href=\"http://stackoverflow.com/questions/6802855/miniprofiler-with-ef-model-first-edmx-model\">MiniProfiler与EF&QUOT;模型第一&QUOT; EDMX模型
和第一缝合在一起用于数据库工作的例子。现在,批准了这一code可能需要拉起和拉出的控制器,但它的工作作为标榜。

I was able to take pieces from this post MiniProfiler with EF "model first" edmx model and stitch together a working example for database first. Now granted this code may need to be pulled up and out of the controller, but it's working as advertised.

作为一个方面说明,我原来的问题,并询问是否有文档中一个拼写错误,我不这么认为,有两个不同的用途和他们是不依赖于对方喜欢我的想法。

As a side note, my original question asked if there was a typo in the documentation and I don't believe so, there a 2 distinct usages and they are NOT dependent upon each other like I thought.

MVC-迷你探查FTW!

mvc-mini-profiler FTW!

问候,
斯蒂芬

Regards, Stephen

    public ActionResult Index()
    {
        // http://code.google.com/p/mvc-mini-profiler/
        // http://stackoverflow.com/questions/6802855/miniprofiler-with-ef-model-first-edmx-model

        var profiler = MiniProfiler.Current;

        var pConn = GetConnection();
        var context = pConn.CreateObjectContext<ChinookEntities>();

        using (profiler.Step("Doing complex stuff"))
        {
            using (profiler.Step("Step A"))
            {
                Thread.Sleep(100);
            }
            using (profiler.Step("Step B"))
            {
                Thread.Sleep(250);
            }
            using (profiler.Step("Step C"))
            {
                var result = context.Albums.AsQueryable()
                    .OrderBy(a => a.ArtistId).First();

                return View(result);
            }
        }
    }

    private static DbConnection GetConnection()
    {
        // A SqlConnection, SqliteConnection ... or whatever
        var connectionString = ConfigurationManager.ConnectionStrings["ChinookEntities"].ConnectionString;
        var ecsb = new EntityConnectionStringBuilder(connectionString);
        var sqlConn = new SqlConnection(ecsb.ProviderConnectionString);
        // wrap the connection with a profiling connection that tracks timings 
        return ProfiledDbConnection.Get(sqlConn, MiniProfiler.Current);
    }

这篇关于MVC-迷你分析器配置澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆