[英]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.