I am writing a .net Core 3.1 application and have recently updated it to Entity Framework Core 5.0. Running the application has since started showing warnings as follows:
The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results.
I have reviewed every instance of my code that would use .Skip or .Take or both and they all have a OrderBy clause.
My question is, are there any flags I can set with
DbContextOptiosnBuilder() .ConfigureWarnings(w => w.Throw(RelationalEventId.???))
to help determine where these .Skip and .Take queries are being ran or any way to trigger a stack trace with this warning to narrow down the cause.
Alternatively, how can one go about silencing this warning from the console?
In fact, you get this warning EVEN if you use a FirstOrDefault
(or SingleOrDefault
) on a primary key selection i.e.
context.dbsetXXX.SingleOrDefaultAsync(xxx => xxx.ID == id);
It seems to be due in how this query in badly mapped in T-SQL - using a TAKE(1)
statement.
So for now I would just Ignore the warning ( using .Ignore(CoreEventId.RowLimitingOperationWithoutOrderByWarning) ...
)
The EventId
value you are looking for is CoreEventId.RowLimitingOperationWithoutOrderByWarning
.
A query uses a row limiting operation (Skip/Take) without OrderBy which may lead to unpredictable results.
This event is in the DbLoggerCategory.Query category.
As usual, the default action is Log
, and you can turn it to error
.Throw(CoreEventId.RowLimitingOperationWithoutOrderByWarning)
or suppress it
.Ignore(CoreEventId.RowLimitingOperationWithoutOrderByWarning)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With