mvc-mini-profiler配置说明 [英] mvc-mini-profiler configuration clarification

查看:147
本文介绍了mvc-mini-profiler配置说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分析器安装在我的MVC 3应用程序中,它的工作原理是什么,但是正确的方法是正确的获取EF 4 db部分的设置。

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 Get方法的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,而我的Model Library没有对Oracle.DataAccess.Client的引用,如果可以的话,我宁愿保持这样。

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.

此外,所有这些代码将驻留在我的存储库中?

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

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

谢谢
Stephen

Thank you, Stephen

推荐答案

我能够从这篇文章中获取 MiniProfiler edmx模型$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $现在授予这个代码可能需要被拉出控制器,但它的工作正如广告。

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-mini-profiler FTW!

mvc-mini-profiler FTW!

问候,
Stephen

Regards, Stephen

    public ActionResult Index()
    {
        // http://code.google.com/p/mvc-mini-profiler/
        // https://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-mini-profiler配置说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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