1

Possible Duplicate:
Help Configure mvc mini profiler with Linq to Sql

We have been using Linq-to-SQL for db persistence. Previously, I was instantiating my DataContext in my repositories like this:

DbContext db = new DbContext();

Now that I want to profile my database using mvc mini profiler, I have used the following approach for creating the DataContext object

partial class DBContext
{
   public static DBContext Get()
   {
      var conn = ProfiledDbConnection.Get(new SqlConnection(connectionString));
      return new DBContext(conn);
   }
}

I get DataContext object nice and fine but when I run Linq queries against this object it gives me null reference exception at methods which were working fine previously. Any ideas why it is behaving this way?
Edit: Ok this is the liqn query which is giving me the null reference exception

var val = (from mod in db.sysModules
                        where
                        mod.ModuleActionResult.ToLower().Equals(actionName.ToLowerInvariant())
                    select mod).SingleOrDefault();

please note that its not db which is null but Expanding the sysModules actually throws the exception. Look at the following screen shot enter image description here when i tried to expand sysmodules in result view here it gives null reference exception. When i instantiated DataContext using new keyword everything works fine.
Edit2: The exception is being thrown at MiniPofiler.cs on AddSqlTiming method. plz have a look at stack trace enter image description here

Community
  • 1
  • 1
Muhammad Adeel Zahid
  • 17,474
  • 14
  • 90
  • 155

0 Answers0