问题描述
EF Core 5.0.5 记录以下内容:
Category: Microsoft.EntityFrameworkCore.Query
EventId: 10103
SpanId: 4d772cc84463cb4c
TraceId: d086e4d89efe374799fcebf1dd354a47
ParentId: 0000000000000000
RequestId: 80000a78-000b-ff00-b63f-84710c7967bb
RequestPath: /xxx/yyy
ActionId: 349a1893-80e4-4d19-9a60-44d1492988a4
ActionName: /xxx/yyy/Index
The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. This may lead to unpredictable results.
但是如果没有调用堆栈,它不是很有帮助。
有没有办法让调用堆栈包含在内?或者,有没有办法关闭仅记录此消息?
解决方法
有没有办法包含调用堆栈?
没有。它不会有帮助。但是您可以打开 Debug
级别的日志记录,这将显示正在构建的查询。
或者,有没有办法关闭仅记录此消息的功能?
是的(和其他任何一样)。对应的键是
CoreEventId.FirstWithoutOrderByAndFilterWarning
和类似的代码:
optionsBuilder.ConfigureWarnings(warnings => warnings
.Ignore(CoreEventId.FirstWithoutOrderByAndFilterWarning)
);