使用 LINQ to SQL 忽略 SQL Server 中的重音

Ignoring accents in SQL Server using LINQ to SQL(使用 LINQ to SQL 忽略 SQL Server 中的重音)
本文介绍了使用 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 中的重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)