dotnet / dotnet/efcore

Prefer equality when comparing values

Open
#34,164 7 comments 2 reactions 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Most databases can take advantage of indexes (and in some cases even auto-generate them) when queries perform equality comparisons (instead of inequality).

In some places EFCore already tries to lean towards equality https://github.com/dotnet/efcore/blob/20edb631265527a73cb9b9ab474cd0484c49a771/src/EFCore.Relational/Query/SqlExpressionFactory.cs#L657-L666

In other places it disregards this and in fact can even replace equality comparisons with inequalities https://github.com/dotnet/efcore/blob/20edb631265527a73cb9b9ab474cd0484c49a771/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs#L1748-L1757 https://github.com/dotnet/efcore/blob/20edb631265527a73cb9b9ab474cd0484c49a771/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs#L1803-L1804

It would be better to avoid converting equalities into inequalities and, when possible, convert inequalities into equalities.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.