简体   繁体   English

如何将有关本地计算表达式的 EF Core 警告转换为错误?

[英]How to turn EF Core warnings about locally evaluated expressions to errors?

Is it possible to turn Entity Framework Core warnings about locally evaluated expressions into errors?是否可以将有关本地计算表达式的 Entity Framework Core 警告转换为错误? I'd like to force myself to always write properly evaluated queries.我想强迫自己总是编写正确评估的查询。

Microsoft.EntityFrameworkCore.Query:Warning: The LINQ expression '(...)' could not be translated and will be evaluated locally. Microsoft.EntityFrameworkCore.Query:警告:LINQ 表达式“(...)”无法翻译,将在本地进行评估。

I'd like to force myself to always write properly evaluated queries.我想强迫自己总是编写正确评估的查询。

Sounds like a good idea.听起来是一个好主意。 Moreover the client evaluation idea has been considered a mistake and will be removed in EF Core 3.0+ , so it's good to be prepared :)此外,客户评估的想法被认为是错误的, 将在 EF Core 3.0+ 中删除,所以做好准备是很好的:)

To get the desired behavior in pre 3.0, you should use the ConfigureWarnings extension method to change the default action from Log to Throw , as explained in the Optional behavior: throw an exception for client evaluation documentation topic:要在 3.0 之前获得所需的行为,您应该使用ConfigureWarnings扩展方法将默认操作从Log更改为Throw ,如可选行为:为客户端评估文档主题抛出异常中所述

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

Additionally, it would be good to do the same for Ignored includes , which are another source of unexpected problems:此外,最好对Ignored includes做同样的事情,这是意外问题的另一个来源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF核心,Any无法翻译,将在本地进行评估 - EF core, Any could not be translated and will be evaluated locally EF Core表达式正在本地评估...为什么? - EF Core expression being evaluated locally… why? EF核心“分组依据无法翻译,将在本地进行评估。” - EF Core “Group By could not be translated and will be evaluated locally.” EF Core ValueObject 比较无法翻译,将在本地评估 - EF Core ValueObject comparison could not be translated and will be evaluated locally LINQ 表达式中的 OData $top 查询无法转换,将使用 EF Core 和 .NET Core 2.2 在本地进行评估 - OData $top query in LINQ expression could not be transalted and will be evaluated locally using EF Core and .NET Core 2.2 如何在EF Core表达式中使用继承的属性? - How to use inherited properties in EF Core expressions? Entity Framework Core 2.2 orderby在本地评估 - Entity Framework Core 2.2 orderby evaluated locally 如何将两个表达式与 Any 链接以制定 EF Core 查询 - How to link two expressions with Any to formulate an EF Core query 如何将 EF Core/LINQ 查询转换为列表<SelectList> ? - How to turn a EF Core/LINQ query into a List<SelectList>? .NET EF Core 模型的 6 个可为 null 的属性警告 - .NET 6 nullable properties warnings for EF Core models
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM