【问题标题】:Call stack for "Uses First/FirstOrDefault/Last/LastOrDefault operation without OrderBy and filter ..." warnings?“使用没有 OrderBy 和过滤器的 First/FirstOrDefault/Last/LastOrDefault 操作...”警告的调用堆栈?
【发布时间】:2021-07-24 10:59:22
【问题描述】:

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.

但是如果没有调用堆栈,它就不是很有帮助。

有没有办法让调用堆栈包含在内?或者有没有办法关闭只记录这条消息?

【问题讨论】:

    标签: logging entity-framework-core warnings


    【解决方案1】:

    有没有办法让调用堆栈包含在内?

    没有。它不会有帮助。但是您可以打开Debug 级别的日志记录,这将显示正在构建的查询。

    或者有没有办法关闭只记录这条消息?

    是的(和其他任何东西一样)。对应的键是

    CoreEventId.FirstWithoutOrderByAndFilterWarning

    和类似的代码:

    optionsBuilder.ConfigureWarnings(warnings => warnings
        .Ignore(CoreEventId.FirstWithoutOrderByAndFilterWarning)
    );
    

    【讨论】:

    • 谢谢。我决定使用 .Throw 而不是 .Ignore,堆栈跟踪正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2021-12-07
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多