Ignoring accents in SQL Server using LINQ to SQL(使用 LINQ to SQL 忽略 SQL Server 中的重音)
问题描述
如何在使用 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+,我记得),您可以通过执行诸如 select MyString, MyId from MyTable where MyString collate Latin1_General_CI_AI =' 来完成此操作啊啊'.
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.
如果您对排序和 select/where 查询总是忽略重音没问题,您可以更改表格以在您关注的字段上指定相同的排序规则.
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 中的重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 LINQ to SQL 忽略 SQL Server 中的重音
基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
