如何使 ASP.NET MVC 迷你分析器与 Linq 2 SQL 一起使用? [英] How can I make the ASP.NET MVC mini profiler work with Linq 2 SQL?

查看:25
本文介绍了如何使 ASP.NET MVC 迷你分析器与 Linq 2 SQL 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC Mini Profiler 看起来很棒,但我不没有得到 Linq 2 SQL 用法示例.

The ASP.NET MVC Mini Profiler looks awesome, but I don't get the Linq 2 SQL usage example.

这是分析器文档中的 Linq2SQL 示例:

This is the Linq2SQL example from the profiler documentation:

partial class DBContext
{
   public static DBContext Get()
   {
      var conn = ProfiledDbConnection.Get(GetConnection());
      return new DBContext(conn);
      // or: return DataContextUtils.CreateDataContext<DBContext>(conn);
   }
}

如何在实际应用中使用它?我本来希望在我的 DataContext 周围有某种包装器,但这似乎以不同的方式工作.我什至不知道示例中的GetConnection()"方法是在哪里定义的.

How do I use this in my actual application? I would have expected some kind of wrapper around my DataContext, but this seems to work in a different way. I don't even know where that that "GetConnection()" method from the example is defined.

谢谢,

阿德里安

推荐答案

终于想通了.如果其他人有同样的问题:

Finally figured it out. In case someone else has the same question:

 private static DataClassesDataContext CreateNewContext()
        {
            var sqlConnection = new SqlConnection(<myconnectionstring>);
            var profiledConnection = ProfiledDbConnection.Get(sqlConnection);
            return DataContextUtils.CreateDataContext<DataClassesDataContext>(profiledConnection);

        }

这篇关于如何使 ASP.NET MVC 迷你分析器与 Linq 2 SQL 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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