首页 > 解决方案 > Dotnet EF Core 2.1 在查询小数属性时抛出 QueryClientEvaluationWarning

问题描述

我有一个 C# 类 Loan,它映射到 SQL Server 数据库中的 Loans 表。我正在使用 DotNet EF Core 2.1。从我的代码与数据库交互。

    public class Loan
    {
       public decimal Rate { get;set; }
       // Other properties omitted for brevity
    }

当我创建数据库连接时,我将其配置为在服务器端无法执行查询时引发异常,如下所示:

    services.AddDbContext<DbContext>(options =>
            options
                .UseSqlServer(systemConfiguration.DatabaseConnectionString)
                .ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)));

问题是使用 LINQ 查询小数列时:

    // Obtain DbContext from services
    var loans = await dbContext.Loans.Where(l => l.Rate > 1.5m).ToListAsync();

由于无法在服务器端执行查询,因此引发异常。其他数字属性类型(例如 int)可以正常工作。

标签: c#linq.net-coreef-core-2.1

解决方案


在针对 SQL Server 运行时,似乎这实际上不是问题。问题出在我使用 SQLite 的集成测试中


推荐阅读