0

I'm trying to get it to record linq-to-sql in the mini profiler as the documentation says

I add this to my App_Code/DataClasses.designer.cs as follows:

public MainContext() : 
        base(global::System.Configuration.ConfigurationManager.ConnectionStrings["ScirraConnectionString"].ConnectionString, mappingSource)
{
    OnCreated();
}

// Code I'm adding in for the mini profiler
partial class DBContext
{
    public static DBContext Get()
    {
        var conn = new MvcMiniProfiler.Data.ProfiledDbConnection(GetConnection(), MiniProfiler.Current);
        return new DBContext(conn);
    }
}

But it throws the error:

The name 'GetConnection' does not exist in the current context  

I've also tried this:

partial class DBContext
{
    public static DBContext Get()
    {
        var conn = ProfiledDbConnection.Get(new System.Data.SqlClient.SqlConnection(global::System.Configuration.ConfigurationManager.ConnectionStrings["ScirraConnectionString"].ConnectionString));
        return new DBContext(conn);
    }
}

But it throws

'MvcMiniProfiler.Data.ProfiledDbConnection' does not contain a definition for 'Get'

I've refered to How can I make the ASP.NET MVC mini profiler work with Linq 2 SQL? but none of the solutions in there seem to work for me.

Can anyone show me how I would get it working for linq-to-sql?

Community
  • 1
  • 1
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456

1 Answers1

1

Your second experient should work if you change this:

ProfiledDbConnection.Get(...)

...to this:

new ProfiledDbConnection(...)

So instead of a static getter you should use the constructor.

I think they changed the API for ProfiledDbConnection somewhere between v1 and v2, and you can still find example code for the older version.

Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132