Alon Gubkin
Alon Gubkin

Reputation: 57129

How to equal two strings case sensitively in Linq to SQL?

How to equal two strings case sensitively in Linq to SQL (in a where query)?

Thanks.

Upvotes: 1

Views: 1262

Answers (3)

Naveen reddy M
Naveen reddy M

Reputation: 21

How to equal two strings case sensitively in Linq to SQL (in a where query)?

Select * from tblemp Where empname='nAveen' COLLATE SQL_Latin1_General_Cp1_CS_AS

Upvotes: 2

Thomas
Thomas

Reputation: 64655

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).

Upvotes: 4

Meta-Knight
Meta-Knight

Reputation: 17875

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.

Upvotes: 3

Related Questions