【问题标题】:How to turn EF Core warnings about locally evaluated expressions to errors?如何将有关本地评估表达式的 EF Core 警告转换为错误?
【发布时间】:2019-08-31 22:26:52
【问题描述】:

是否可以将有关本地评估表达式的 Entity Framework Core 警告转换为错误?我想强迫自己始终编写正确评估的查询。

Microsoft.EntityFrameworkCore.Query:Warning:无法翻译 LINQ 表达式“(...)”,将在本地计算。

【问题讨论】:

标签: c# asp.net-core entity-framework-core


【解决方案1】:

我想强迫自己始终编写正确评估的查询。

听起来是个好主意。而且客户评价的想法已经被认为是错误的will be removed in EF Core 3.0+,所以做好准备就好了:)

要在 3.0 之前获得所需的行为,您应该使用 ConfigureWarnings 扩展方法将默认操作从 Log 更改为 Throw,如 Optional behavior: throw an exception for client evaluation 文档主题中所述:

optionsBuilder.ConfigureWarnings(warnings => warnings
    .Throw(RelationalEventId.QueryClientEvaluationWarning)
);

此外,最好对Ignored includes 执行相同操作,这是意外问题的另一个来源:

.Throw(RelationalEventId.QueryClientEvaluationWarning)
.Throw(CoreEventId.IncludeIgnoredWarning)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2013-04-11
    相关资源
    最近更新 更多