2011-06-09 54 views
18

ASP.NET MVC Mini Profiler看起来很棒,但我没有得到Linq 2 SQL的使用示例。如何使ASP.NET MVC迷你探查器与Linq 2 SQL一起工作?

这是从探查文档LINQ2SQL例如:

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

如何我在实际应用中使用?我会期望在我的DataContext中使用某种包装,但是这似乎以不同的方式工作。我甚至不知道该例中的“GetConnection()”方法在哪里定义。

感谢,

阿德里安

回答

7

终于搞明白了。如果其他人有相同的问题:

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

     } 
+4

整点是,它是在安全生产中使用,有没有需要做的#if DEBUG东西......如果会话不分析获取将返回原始连接 – 2011-06-09 23:30:20

+0

即时通讯使用迷你分析器与LINQ到SQL PLZ看看http://stackoverflow.com/questions/6410756/using-different-overload-of-datacontext- in-linq-to-sql – 2011-06-21 06:09:18

+0

你把这个方法放在哪里?你打算如何调用它? – RyanW 2011-08-26 15:53:29

3

的getConnection()是将返回的DbConnection的功能。你可能只是做

var conn = ProfiledDbConnection.Get(new System.Data.SqlClient.SqlConnection(your_connection_string)); 

改为。

6

没有其他答案为我工作。在我DataClasses.Designer.cs添加此我DataClassesDataContext阶级都:

public static DataClassesDataContext CreateNewContext() 
{ 
    var sqlConnection = new DataClassesDataContext().Connection; 
    var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(sqlConnection); 
    return new DataClassesDataContext(profiledConnection); 
} 
+3

似乎不适用于我,ProfiledDConnection上没有定义Get()方法。 – RyanW 2011-08-26 16:07:47

+2

@RyanW'改为使用新的ProfiledDbConnection(sqlConnection,MiniProfiler.Current)'。 – 2012-07-13 11:26:22

相关问题