在EF 4.1 code-第一个项目MVC-迷你探查V1.7没有轮廓SQL [英] Mvc-Mini-Profiler v1.7 on EF 4.1 Code-First project doesn't profile SQL

查看:113
本文介绍了在EF 4.1 code-第一个项目MVC-迷你探查V1.7没有轮廓SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装MiniProfiler.MVC3 - 1.7包在我的项目昨天。控制器和视图分析工作正常,但我真正感兴趣的peice的是SQL事件探查。我一直没能得到这个工作。我使用的是EF code先用SQL 2008数据库。

I setup MiniProfiler.MVC3 - 1.7 package in my project yesterday. The Controller and view profiling is working fine, but the peice I'm really interested in is the SQL Profiling. I have not been able to get this to work. I'm using EF Code First with a SQL 2008 database.

我已经遵循了这一职位的所有建议。

I have followed all the suggestions in this post ..

<一个href=\"http://stackoverflow.com/questions/6757659/mvcminiprofiler-on-ef-4-1-$c$c-first-project-doesnt-profile-sql/6800657#6800657\">mvcminiprofiler-on-ef-4-1-$c$c-first-project-doesnt-profile-sql

在miniprofiler.cs我有我的SQL连接设置为...

In the miniprofiler.cs i have my SQL connection setup as...

 var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["CMDBMVC3"].ConnectionString);

我的web.config数据库连接为...

My Web.config db connection is...

 <add name="CMDBMVC3" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI; AttachDBFilename=|DataDirectory|CMDB_MVC3.mdf;Initial Catalog=CMDB_MVC3;Trusted_Connection=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

如果我把一个断点在迷你探查行就指向正确的数据库连接。我不知道还有什么在这一点上做的。我想AP preciate如何获得SQL分析工作的任何方向。

If I put a breakpoint on the mini-profiler line it points to the correct db connection. I'm not sure what else to do at this point. I would appreciate any direction on how to get the SQL profiling working.

推荐答案

我第一次使用EF code和我的上下文构造内的迷你探查我创建一个新的连接工厂和它传递给ProfiledDbConnectionFactory方法这将返回异形连接,然后可以设置为背景的DefaultConnectionFactory。

I use EF Code first and the mini profiler within my Context constructor I create a new connection factory and pass this to the ProfiledDbConnectionFactory method this returns a profiled connection that you can then set as the DefaultConnectionFactory of the context.

public MyConext()
{
    var factory = new ConnectionFactory(); 
    var profiled = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(factory);
    Database.DefaultConnectionFactory = profiled;
}

连接制造工厂只返回一个新的SQL连接

The connection Facotry just returns a new sql connection

public class ConnectionFactory :IDbConnectionFactory
{
     public DbConnection CreateConnection()
     {
         var cnn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["SomeConnection"].ToString());

             return cnn;            
    }

您还需要将ProfiledDBProvider添加到Web配置文件。确认版本号是正确的适合你。

You also need to add the ProfiledDBProvider to the web config file. Make sure the version number is correct for you.

<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>
  </system.data>

这工作正常,我在这两个MVC和使用Miniprofiler的NuGet包asp.net web表单。我还检查出的NuGet包汽车CONFIGS分析的新的MVC版本作为全球行动滤波器的一部分。

This works fine for me in both MVC and asp.net webforms using the Miniprofiler nuget package. I'd also check out the new MVC version of the nuget package that auto configs profiling as part of a global action filter.

这篇关于在EF 4.1 code-第一个项目MVC-迷你探查V1.7没有轮廓SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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