How can I add information to every SqlCommand emitted by DbContext?

I am trying to write a module to add a comment containing useful information to each Linq2Entities SQL query emitted by the DbContext entity DbContext (the information will be used during debugging).

Using Linq2Sql , I previously did this by expanding the MvcMiniProfiler ProfiledDbCommand command class. However, I cannot use the same approach for working with EF / DbContext. I am extending EFProfiledDbCommand , but this does not work. In fact, even the direct use of EFProfiledDbCommand does not work: I get an error

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

Can someone provide a workaround for my current solution or an alternative approach to this problem?

+6
source share
1 answer

It looks like the answer is in a comment from @Giorgio: How do you use mvc-mini-profiler with Entity Framework 4.1 and Using mvc-mini-profiler profile profiling with Entity Framework Code First and it is most easy to solve by adding MiniProfiler.EF package NuGet.

+1
source

Source: https://habr.com/ru/post/908380/


All Articles