Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I append information to every SqlCommand emitted by a DbContext?

I am trying to write a module to append a comment containing useful information to every Linq2Entities SQL query emitted by an entity framework DbContext (the information will be used in debugging).

Using Linq2Sql, I had previously accomplished this via extending the MvcMiniProfiler ProfiledDbCommand command class. However, I can't get the same approach to work with EF/DbContext. I've extending EFProfiledDbCommand, but that doesn't work. Indeed, even a straight use of EFProfiledDbCommand doesn't work: I get the error

Unable to determine the provider name for connection of type 'MvcMiniProfiler.Data.EFProfiledDbConnection'.

Can anyone supply either workaround for my current solution or an alternate approach to this problem?

like image 341
ChaseMedallion Avatar asked Feb 13 '12 22:02

ChaseMedallion


1 Answers

It appears the answer is in the comment by @Giorgio: How do you use the mvc-mini-profiler with Entity Framework 4.1 and Using mvc-mini-profiler database profiling with Entity Framework Code First and is most easily solved by adding MiniProfiler.EF NuGet package.

like image 144
robrich Avatar answered Oct 15 '22 02:10

robrich