我们正在使用 newrelic 进行数据库性能监控。我们的问题是实体框架正在生成 SQL,并且我们在跟踪此 SQL 查询在我们的代码库中生成的位置时遇到问题,例如
假设以下查询导致性能问题。例如,如何修改生成的 sql 查询并在其上添加自定义注释
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…
那么我该如何做这样的事情 var DbContext.MyDbSet.Where(myWhereEx).AddCustomComment("Hello this is a custom comment I will write it from my code")
之后的输出将是这样的
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
我的问题是如何实现 AddCustomComment 并在 AddCustomComment 内部修改生成的 sql 在它进入 SQL 服务器之前