How to "tag" Entity platform queries

I help improve the performance of a complex application with hundreds of Entity Framework queries scattered throughout the code base. One of the problems is that when we run SQL Profiler and capture Entity Framework queries, it is very difficult to find the code that actually led to the execution of the SQL query that comes to the profiler. I am wondering if it is possible to “tag” in some way each entity framework statement with a unique identifier, which will be presented in the sql statement. Something like adding a comment to the actual sql statement that the entity infrastructure creates for each statement. Then we could see the comment in the profiler trace and search for the code for the tag. Any ideas on how we can do this? I guess,that we must somehow intercept the sql that EF generates and add our comment to it before it goes to the db server.

+4
source share
1 answer

I personally would use a code profiler rather than an SQL profiler (I prefer JetBrain dotTrace). The Entity Framework sometimes generates several requests depending on the operation it performs, so it will not be trivial to mark every request that you see for a specific operation, because it does not necessarily find it in every request.

, EF - , linq, , . , , , , SQL-.

+1

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


All Articles