Entity framework EF Core 5.0,其中谓词在存储在变量中时被忽略

Entity framework EF Core 5.0,其中谓词在存储在变量中时被忽略,entity-framework,entity-framework-core,ef-core-5.0,Entity Framework,Entity Framework Core,Ef Core 5.0,更新到EF Core 5.0后,我注意到长时间运行的查询。 也许我发现了EF Core 5.0漏洞,但也许这是一个突破性的改变,我在这里没有发现 我有一个函数,它把where谓词作为参数,所以这是我不能轻易重写的 有效的代码: 并生成包含WHERE子句的正确查询: SELECT [r].[ReportID], [r].[AdvancedFilterPurpose] -- ommited columns FROM [report].[Reports] AS [r] LEFT

更新到EF Core 5.0后,我注意到长时间运行的查询。 也许我发现了EF Core 5.0漏洞,但也许这是一个突破性的改变,我在这里没有发现

我有一个函数,它把where谓词作为参数,所以这是我不能轻易重写的

有效的代码:

并生成包含WHERE子句的正确查询:

SELECT [r].[ReportID], [r].[AdvancedFilterPurpose] -- ommited columns
      FROM [report].[Reports] AS [r]
      LEFT JOIN [report].[ReportColumns] AS [r0] ON [r].[ReportID] = [r0].[ReportID]
      WHERE [r].[Name] = N'ListOfCustomers'
      ORDER BY [r].[ReportID], [r0].[ReportColumnID]
不起作用的代码:

谢谢您的建议。

用表达式替换类型Func

这不起作用:Func a=r=>r.Name==ListOfCustomers

这将起作用:表达式a=r=>r.Name==ListOfCustomers

SELECT [r].[ReportID], [r].[AdvancedFilterPurpose] -- ommited columns
      FROM [report].[Reports] AS [r]
      LEFT JOIN [report].[ReportColumns] AS [r0] ON [r].[ReportID] = [r0].[ReportID]
      WHERE [r].[Name] = N'ListOfCustomers'
      ORDER BY [r].[ReportID], [r0].[ReportColumnID]
Func<Db.Model.Report, bool> a = (r) => r.Name == "ListOfCustomers";
var reps = ctx.Reports.AsNoTracking()
              .Include(r => r.ReportColumns)
              .Where(a)
              .ToList();
SELECT [r].[ReportID], [r].[AdvancedFilterPurpose] -- ommited columns  
      FROM [report].[Reports] AS [r]
      LEFT JOIN [report].[ReportColumns] AS [r0] ON [r].[ReportID] = [r0].[ReportID]
      ORDER BY [r].[ReportID], [r0].[ReportColumnID]