We are using newrelic for Database performance monitoring. Our problems is Entity framework is generating SQL and we are having issues tracking where this SQL query was generated in our code base for example
Lets say the below query is causing performance issues. How can I modify the generated sql query and add custom comment on it for example
SELECT
? AS [C1],
[GroupBy1].[K1] AS [Destination],
[GroupBy1].[A1] AS [C2]
FROM ( SELECT
[Extent1].[Destination] AS [K1],
SUM([Extent1].[SearchCount]) AS [A1]
FROM [Flight].[Item] AS [Extent1]
WHERE ([Extent1].[Origin] IN (?, ?)) AND ( NOT ((@p__linq__0 = ?) AND ([Extent1].[IsDomesticTurkish] = ?))) AND ([Extent1].[DestinationCity] IN (?, ?, ?, ?, ?, ?, ?, ?)) AND ([Extent1].[DestinationCity] IS NOT NULL)
GROUP BY [Extent1...More…
So How can I do something like this var DbContext.MyDbSet.Where(myWhereEx).AddCustomComment("Hello this is a custom comment I will write it from my code")
After that The output will be like this
SELECT
? AS [C1],
[GroupBy1].[K1] AS [Destination],
[GroupBy1].[A1] AS [C2]
FROM ( SELECT
[Extent1].[Destination] AS [K1],
SUM([Extent1].[SearchCount]) AS [A1]
FROM [Flight].[Item] AS [Extent1]
WHERE ([Extent1].[Origin] IN (?, ?)) AND ( NOT ((@p__linq__0 = ?) AND ([Extent1].[IsDomesticTurkish] = ?))) AND ([Extent1].[DestinationCity] IN (?, ?, ?, ?, ?, ?, ?, ?)) AND ([Extent1].[DestinationCity] IS NOT NULL)
GROUP BY [Extent1...More…
--Hello this is a custom comment I will write it from my code
My question is how to implement AddCustomComment and inside AddCustomComment modify the generated sql before it goes to SQL server