我想知道如何在LinqToSql中跟踪生成的SQL,如DataContext.
我还在Jaroslaw Kowalski的博客上阅读了有关EFProviderWrapper解决方案的文章,但它基于ObjectContext,不适用于DbContext.
任何人都知道如何在DbContext中执行此操作?
谢谢.
我引用了MvcMiniProfiler的1.6版本(通过Nuget),并按照项目主页http://code.google.com/p/mvc-mini-profiler/上的说明设置了所有内容.
我在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.6.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
</DbProviderFactories>
</system.data>
Run Code Online (Sandbox Code Playgroud)
(项目主页的版本= 1.5.0.0 - NuGet包已经更新)
我在Global.asax中有以下代码(以及在Web.config中定义的连接字符串):
protected void Application_Start()
{
Log.Info("ReCoupon has started.");
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var factory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["ReCouponContext"].ConnectionString);
var profiled = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(factory);
Database.DefaultConnectionFactory = profiled;
Database.SetInitializer(new ReCouponContextInitializer());
}
Run Code Online (Sandbox Code Playgroud)
分析器工作得很好,除了我不能让它来分析SQL.我正在使用SQL Server 2008 Express.我一直在关注Google Code项目主页上的相关问题而且完全陷入困境.
code-first entity-framework-4 asp.net-mvc-3 mvc-mini-profiler
我试图使用mvc-mini-profiler与MVC3并继续得到以下错误
无法确定连接类型为"MvcMiniProfiler.Data.ProfiledDbConnection"的提供程序名称
下面是我用来尝试和实现我的Context的代码.
DbConnection conn = new MySqlConnection(
ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(conn);
return new DB(profiledConnection);
Run Code Online (Sandbox Code Playgroud)
这是DB Context Class.
public class DB:DbContext, Stats.Data.IDB
{
public DB(DbConnection conn)
: base(conn, true)
{
}...
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个模块,将包含有用信息的注释附加到Linq2Entities实体框架发出的每个SQL查询中DbContext(该信息将用于调试).
使用Linq2Sql,我之前通过扩展MvcMiniProfiler ProfiledDbCommand命令类来完成此操作.但是,我无法使用相同的方法来使用EF/DbContext.我正在扩展EFProfiledDbCommand,但这不起作用.实际上,即使直接使用EFProfiledDbCommand也行不通:我得到了错误
无法确定"MvcMiniProfiler.Data.EFProfiledDbConnection"类型的连接的提供者名称.
任何人都可以为我当前的解决方案提供解决方法或解决此问题的替代方法吗?