mvc-mini-profiler configuration clarification

别来无恙 提交于 2019-12-04 23:17:01
Stephen Patten

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!

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);
    }
Andiih

I was going to say that the mini-profiler was 4.0 only, but its been recently updated. This might help (although you are not code first)

Using mvc-mini-profiler database profiling with Entity Framework Code First

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!