1.7 .NET MVC3和EF code首先升级到1.9 MvcMiniProfiler [英] Upgrading to MvcMiniProfiler 1.9 from 1.7 .NET MVC3 and EF Code First

查看:150
本文介绍了1.7 .NET MVC3和EF code首先升级到1.9 MvcMiniProfiler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我已经跌回进入,我没有一直与在过去一个月左右的项目。我不得不使用MiniProfiler 1.7本项目配置,一切都很好世界。它异型我的数据库调用和视图的表现也是如此。

Today I've dropped back into a project that I haven't been working with for the past month or so. I had this project configured using MiniProfiler 1.7 and all was well in the world. It profiled my DB calls and the view performance as well.

我决定升级到1.9,我已经遇到了一些减速带。现在,我已经通过的大多数问题在这一点上工作过。似乎错误的唯一事情是DB剖析。我越来越下降了死亡的黄色画面,出现以下错误:

I decided to upgrade to 1.9 and I've run into a few speed bumps. Now, I've worked through most of the issues at this point. The only thing that seems "wrong" is DB profiling. I'm getting dropped a yellow screen of death with the following error:

A null was returned after calling the 'get_ProviderFactory' method on a store 
provider instance of type 'MvcMiniProfiler.Data.ProfiledDbConnection'. 
The store provider might not be functioning correctly.

有关参考,让我告诉你我是如何在1.7有miniprofiler设置与MVC3和EF 4.1 code首先

For reference, let me show you how I had miniprofiler setup in 1.7 with MVC3 and EF 4.1 Code First.

的web.config

web.config

  <system.data>
<DbProviderFactories>
  <remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" />
  <add name="MvcMiniProfiler.Data.ProfiledDbProvider" 
       invariant="MvcMiniProfiler.Data.ProfiledDbProvider" 
       description="MvcMiniProfiler.Data.ProfiledDbProvider" 
       type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler, Version=1.7.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>

Global.asax中从那里处理了大部分的一切。我会列出相关的Application_Start()code,现在没有以前的工作。

Global.asax handled most everything from there. I'll list the relevant Application_Start() code that worked prior that doesn't now.

#region MVC Mini Profiler related database profiling config/setup

        //This line makes SQL Formatting smarter so you can copy/paste 
        // from the profiler directly into Query Analyzer
        MiniProfiler.Settings.SqlFormatter = new SqlServerFormatter();

        var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
        var profiled = new ProfiledDbConnectionFactory(factory);
        Database.DefaultConnectionFactory = profiled;

#endregion

在我的上下文中的最后一步是在异形连接挂钩:

With the last step being in my context hooking in the profiled connection:

public class Database : DbContext
{
    public Database()
        : base(GetProfilerConnection(), true)
    {}

    private static DbConnection GetProfilerConnection()
    {
        return
            ProfiledDbConnection.Get(
                new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString));
    }
}

快进到今天,我已经重新设计的东西用MVC3 minprofiler的NuGet包和​​EF miniprofiler的NuGet包,但我失去了对如何让数据库分析工作了。

Fast forward to today and I've reworked things to use the MVC3 minprofiler nuget package and the EF miniprofiler NuGet package, but I'm lost on how to get DB profiling working again.

我修改我的web.config到似乎的是什么必需的,但ReSharper的不开心第一关。

I've modified my web.config to the following which seemed to be what was required but ReSharper isn't happy first off.

  <system.data>
<DbProviderFactories>
  <remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" />
  <add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider"
       description="MvcMiniProfiler.Data.ProfiledDbProvider"
       type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler.EntityFramework, Version=1.9.1.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>

不太清楚,我在这里失踪。我甚至有一个MiniProfilerEF.Initialize调用需要这个了();?一些文件和建议似乎表明你甚至不需要这个了。

Not quite sure what I'm missing here. Do I even need this anymore with a call to MiniProfilerEF.Initialize();? Some documentation and suggestions seem to indicate you don't even need this anymore.

更重要的问题是如何建立DB剖析1.9。

The bigger problem is how to setup DB Profiling in 1.9.

相关code,我曾在之前的Global.asax现在已经搬进了App_Start文件夹MiniProfiler.cs。我想设置本来相同的,但这并不会出现这种情况。

The relevant code that I had prior in Global.asax has now been moved into MiniProfiler.cs in the App_Start folder. I figured the setup would have been the same but that doesn't appear to be the case.

我想这样做(也许是因为这正是我熟悉的1.7)

I want to do this (perhaps because this is just what I'm familiar with in 1.7)

//TODO: To profile a standard DbConnection: 
        var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
        var profiled = new ProfiledDbConnectionFactory(factory);
        Database.DefaultConnectionFactory = profiled;

这似乎并没有工作下去了。我也注意到,看来我应该使用EFProfiledDbConnection现在,而不是仅仅ProfiledDbConnection?这是正确的?

This doesn't seem to work any longer. I've also noted that it seems I should be using EFProfiledDbConnection now instead of just ProfiledDbConnection? Is this correct?

我如何去了解这个模型配置数据库分析?我挖高和低通过的文件,但与新的方式混合的老路上这么多信息,我有一个很难分离今天的正确的方法是什么。

How do I go about configuring DB profiling with this model? I'm digging high and low through documentation, but there's so much information with the old way mixed in with the new way and I'm having a hard time separating what the "correct" way is today.

推荐答案

唉,对不起你们。

我解决了这个问题。

我不得不添加的EF MVCMiniProfiler的NuGet包在我的数据模型的项目,并更改连接,所以输入那里EFProfiledConnection:

I had to add the EF MVCMiniProfiler NuGet package in my data model project and change the connection type there to EFProfiledConnection as so:

        /// <summary>
    /// Supply our own connection string to the DBContext to utilize mini-profiler for SQL queries as well.
    /// </summary>
    /// <returns>DBConnection</returns>
    private static DbConnection GetProfilerConnection()
    {
        return new EFProfiledDbConnection(new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString),
                                        MiniProfiler.Current);
    }

想这应该是明显,我看着EF是如何分解成它自己的连接类型。

Guess that should have been obvious to me looking at how EF was broken out into it's own connection type.

我也注释掉的配置设置,所以我可以证实,他们不再需要了。

I also commented out the config settings so I can confirm that they're no longer required.

我不知道这是否是配置EF和MVC迷你1.9的正确的方式,但它的作品。

I don't know if this is the "right" way of configuring EF and MVC Mini 1.9, but it works.

我愿意就改进建议或是否有这样做的更多的正确的办法,但现在我回来重新启动和运行。

I'm open to suggestions on improvement or if there's a more correct way of doing this, but for now I'm back up and running again.

这篇关于1.7 .NET MVC3和EF code首先升级到1.9 MvcMiniProfiler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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