How to equal two strings case sensitively in Linq to SQL (in a where query)?
Thanks.
How to equal two strings case sensitively in Linq to SQL (in a where query)?
Thanks.
You'll have to make the field in question case-sensitive in SQL Server (or whatever DBMS you use). If you use SQL Server, look for the Collation field property, in there you can set case sensitivity.
You cannot do it solely within LINQ to SQL. From the documentation:
Unsupported System.String Methods in General
Queries do not account for SQL Server collations that might be in effect on the server, and therefore will provide culture-sensitive, case-insensitive comparisons by default. This behavior differs from the default, case-sensitive semantics of the .NET Framework.
The way to do it is in your own query where you specify the collation:
Select...
From Table
Where Column = "Value" COLLATE SQL_Latin1_General_CP1_CS_AS
Note that the collation I'm providing specifies a case-sensitive match (CS).