使用 LINQ to SQL 忽略 SQL Server 中的重音 [英] Ignoring accents in SQL Server using LINQ to SQL

查看:29
本文介绍了使用 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 collat​​e 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 中的重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆