Skip to content

Instantly share code, notes, and snippets.

@plaurin
Last active December 12, 2015 02:59
Show Gist options
  • Save plaurin/4703605 to your computer and use it in GitHub Desktop.
Save plaurin/4703605 to your computer and use it in GitHub Desktop.
Example using MiniProfiler
MiniProfilerEF.Initialize_EF42(); // When using Code First
ConsoleProfiling.Start();
using (StackExchange.Profiling.MiniProfiler.Current.Step("StepName"))
{
using (var context = new Context())
{
var result = context.Entities
.Where(p => p.Property.StartsWith("Value"))
.ToList();
}
}
foreach (var sqlTiming in ConsoleProfiling.StopAndGetProfiler().GetSqlTimings())
{
Console.WriteLine("Duration: " + sqlTiming.DurationMilliseconds);
Console.WriteLine(sqlTiming.CommandString);
if (sqlTiming.Parameters != null)
{
foreach (var parameter in sqlTiming.Parameters)
Console.WriteLine(parameter.Name + ": " + parameter.Value);
}
Console.WriteLine("------------------");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment