I have a 2 tier web application. DataAccess and WebSite.
So in my dataContext.cs
on the DataAccess tier I added the wrapper...
//The autogenreated context when I made the linq2sql class
public static MyDataContext DataContext
{
get
{
//We are in a web app, use a request scope
if (HttpContext.Current != null)
{
if (HttpContext.Current.Items["dc"] == null)
{
MyDataContext dc = new MyDataContext ();
HttpContext.Current.Items["dc"] = dc;
return dc;
}
else
return (MyDataContext )HttpContext.Current.Items["dc"];
}
else
{
if (dataContext == null)
dataContext = new MyDataContext ();
return dataContext;
}
}
}
//the method I added to the autogenreated contex in
//an attempt to wrap the profiler around it
public static MyDataContext Get()
{
var sqlConnection = new MyDataContext().Connection;
var profiledConnection = new StackExchange.Profiling.Data.ProfiledDbConnection(sqlConnection, MiniProfiler.Current);
return new MyDataContext(profiledConnection);
}
So this is what the profileConnection looks like when it gets called but before the return New MyDataContext(porofiledConnection)
and in my business logic also in the DataAccess tier I made sure that the db context is all created with db = MyDataContext.Get()
in stead of db = new MyDataContext();
public class MyOrders(){
private static MyDataContext db = MyDataContext.Get();
public static List<model> GetOrderHistory(){
var = db.MyStoredProcedure(args) //Inspecting here before execution
//proces result and return list of model
}
}
Now, on some pages I used to get SQL lines and I could click on them and inspect them. But after I browsed the site it just shows this - no SQL lines any more? Like this page just randomly shows me SQL duplication- But if I reload it is gone.
And on this page that I never ran with the profiler before that has loading time issues I cannot identify the SQL it used.
Did I miss something? Is the SQL cached? I always want to see the SQL even if Linq2Sql caches it or whatever. What did I do wrong?