使用LINQ to SQL忽略SQL Server中的重音符号 [英] Ignoring accents in SQL Server using LINQ to SQL
问题描述
在使用LINQ to SQL对SQL Server数据库进行查询时,如何忽略重音(例如´,`,〜)?
How can I ignore accents (like ´, `, ~) in queries made to a SQL Server database using LINQ to SQL?
更新:
仍然没有弄清楚如何在LINQ中做到这一点(或者即使有可能),但是我设法更改数据库来解决此问题. 只需更改我要搜索的字段上的排序规则即可.我的排序规则是:
Still haven't figured out how to do it in LINQ (or even if it's possible) but I managed to change the database to solve this issue. Just had to change the collation on the fields I wanted to search on. The collation I had was:
SQL_Latin1_General_CP1_CI_AS
CI表示不区分大小写",AS表示区分重音".只需将AS更改为AI,以使其对不区分重音"即可. SQL语句是这样的:
The CI stans for "Case Insensitive" and AS for "Accent Sensitive". Just had to change the AS to AI to make it "Accent Insensitive". The SQL statement is this:
ALTER TABLE table_name ALTER COLUMN column_name column_type COLLATE collation_type
推荐答案
在SQL查询(我记得是Sql Server 2000+)中,您可以通过执行以下操作来执行此操作:从MyTable中选择MyString,MyId,其中MyString整理Latin1_General_CI_AI =' aaaa'.
In SQL queries (Sql Server 2000+, as I recall), you do this by doing something like select MyString, MyId from MyTable where MyString collate Latin1_General_CI_AI ='aaaa'.
我不确定在Linq中是否可以实现,但是更熟悉Linq的人可能会翻译.
I'm not sure if this is possible in Linq, but someone more cozy with Linq can probably translate.
如果您对排序和选择/查询始终满意,可以忽略重音符号,则可以更改表以在与您关注的字段上指定相同的排序规则.
If you are ok with sorting and select/where queries ALWAYS ignoring accents, you can alter the table to specify the same collation on the field(s) with which you are concerned.
这篇关于使用LINQ to SQL忽略SQL Server中的重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!