Adr*_*ore 18 asp.net-mvc linq-to-sql mvc-mini-profiler
在ASP.NET MVC迷你探查看起来真棒,但我不明白的LINQ的2 SQL使用示例.
这是profiler文档中的Linq2SQL示例:
partial class DBContext
{
public static DBContext Get()
{
var conn = ProfiledDbConnection.Get(GetConnection());
return new DBContext(conn);
// or: return DataContextUtils.CreateDataContext<DBContext>(conn);
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在实际应用中使用它?我本来期望我的DataContext有一些包装器,但这似乎以不同的方式工作.我甚至不知道定义了示例中的"GetConnection()"方法的位置.
谢谢,
阿德里安
终于想通了.如果其他人有同样的问题:
private static DataClassesDataContext CreateNewContext()
{
var sqlConnection = new SqlConnection(<myconnectionstring>);
var profiledConnection = ProfiledDbConnection.Get(sqlConnection);
return DataContextUtils.CreateDataContext<DataClassesDataContext>(profiledConnection);
}
Run Code Online (Sandbox Code Playgroud)
没有其他答案对我有用.将它添加到我的DataClasses.Designer.cs中的DataClassesDataContext类中:
public static DataClassesDataContext CreateNewContext()
{
var sqlConnection = new DataClassesDataContext().Connection;
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(sqlConnection);
return new DataClassesDataContext(profiledConnection);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1576 次 |
| 最近记录: |