Prefer equality when comparing values
- 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
Assessment
This issue has not been assessed yet.