roslynator
roslynator copied to clipboard
RCS1155: use StringComparison false positive
Product and Version Used: Roslynator 2.3.0 Visual Studio 16.4.4
Steps to Reproduce:
Consider this Linq code running against a SQL database with a case sensitive collation.
This is attempting to do a case insensitive search
KitJournals.Where (k => k.UserId.ToUpper() == "osullirx".ToUpper()).Dump();
and results in this SQL
SELECT
...
FROM [dbo].[KitJournal] AS [Extent1]
WHERE ((UPPER([Extent1].[UserId])) = (UPPER(N'osullirx')))
OR ((UPPER([Extent1].[UserId]) IS NULL) AND (UPPER(N'osullirx') IS NULL))
Accepting RCS1155 suggestion changes the code to:
KitJournals.Where (k => k.UserId.Equals("osullirx", StringComparison.OrdinalIgnoreCase)).Dump();
which results in this SQL which does a case sensitive search, the opposite of what was expected
SELECT
...
FROM [dbo].[KitJournal] AS [Extent1]
WHERE N'osullirx' = [Extent1].[UserId]
Possible duplicate of #440