Begins query profiling for a datacontext instance. This overload initiates a unfiltered profiler session without execution plan logging and synchronous log writes. See other overloaded implementations for additional options.

Namespace: Huagati.LinqToSQL.Profiler
Assembly: HuagatiL2SProfiler (in HuagatiL2SProfiler.dll) Version: 1.33.3996.16059

Syntax

C#
public static QueryProfiler BeginProfiling(
	this DataContext dc,
	string outputPath
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function BeginProfiling ( _
	dc As DataContext, _
	outputPath As String _
) As QueryProfiler
Visual C++
[ExtensionAttribute]
public:
static QueryProfiler^ BeginProfiling(
	DataContext^ dc, 
	String^ outputPath
)

Parameters

dc
Type: System.Data.Linq..::..DataContext
DataContext to profile
outputPath
Type: System..::..String
Output path or URL to the profiler query log.

Return Value

Returns a QueryProfiler instance representing the current profiler session.

Examples

This example shows how to use the DataContext extension method BeginProfiling to set up profiling from within an application.
CopyC#
using (MyDataContext dc = new MyDataContext())
{
    //initialize profiling - profiler logs can be saved to a local path or to a URL.
    QueryProfiler qp = dc.BeginProfiling(@"c:\temp\profilerOutput");

    //define a query
    var query = from emp in dc.Employees where emp.EmployeeAddresses.Address.City == "London" select emp;

    //enumerate employees
    foreach (Employee emp in dc.Employees)
    {
        System.Diagnostics.Debug.WriteLine(emp.EmployeeID.ToString());
    }

    //disable profiling
    qp.EndProfiling();
}
Alternatively, override the datacontext constructor with a constructor that initialize profiling and a dispose method that terminates profiling:
CopyC#
public partial class MyDataContext
{
    private QueryProfiler _profiler = null;

    public MyDataContext(bool enableProfiling) : this()
    {
        if (enableProfiling == true)
        {
            string profilerOutput = @"https://apps.huagati.com/queryprofiler/?logid=7382";
            _profiler = this.BeginProfiling(profilerOutput);
        }
    }

    protected override void Dispose(bool disposing)
    {
        if (_profiler != null)
        {
            this.EndProfiling();
        }
        base.Dispose(disposing);
    }
}

See Also