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

和自甴很熟 提交于 2019-12-23 04:24:20

问题


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

Thanks.


回答1:


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




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/2600932/how-to-equal-two-strings-case-sensitively-in-linq-to-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!