仅显示 EF 在 SQL Profiler 中进行的查询

Show only queries made by EF in SQL Profiler

如何在 SQL Profiler 中仅显示 EF 进行的查询?

如您在屏幕截图中所见,以红色突出显示的查询是我在 EF 的帮助下创建的查询。所有其他的都是从其他地方生成的,我想隐藏它们。

可能吗?

更新

当我尝试在连接字符串中指定 applicationName 时出现错误。

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
            if (!optionsBuilder.IsConfigured) {     

optionsBuilder.UseSqlServer("Server=.\;Database=AdventureWorksLT2012;Trusted_Connection=True;applicationName=FOO_NAME");
            }
        }

Unhandled exception. System.ArgumentException: Keyword not supported: 'applicationname'. at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary2 parsetable, String connectionString, Boolean buildChain, Dictionary2 synonyms, Boolean firstKey) at Microsoft.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)

我在这里错过了什么?

当您的 EF DbContext 有自己的连接字符串时,您可以在连接字符串中设置“;Application Name=EF”,并在探查器中过滤此应用程序名称。

您可以在连接时的“跟踪属性”对话框中执行此操作

  • select 事件选择选项卡
  • 单击按钮列过滤器...
  • 将连接字符串中的应用程序名称添加到 属性 ApplicationName。您也可以使用其他过滤器,例如主机名,如果你勾选 'Show all columns'.

连接到服务器后,按工具栏中的“属性”图标并执行相同操作。