roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

RCS1155: use StringComparison false positive

Open PhilPJL opened this issue 5 years ago • 1 comments

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]

PhilPJL avatar Feb 05 '20 19:02 PhilPJL

Possible duplicate of #440

josefpihrt avatar Feb 07 '20 11:02 josefpihrt