与不区分大小写字符串比较LINQ到SQL和LINQ到对象大小写、字符串、对象、LINQ

2023-09-04 00:53:38 作者:曲终人尽散╮物是已人非

又见Differences LINQ之间的对象和LINQ to SQL查询

我们都在我们的数据库使用的一些查询和我们的内存中的对象

什么是LINQ到SQL做一个不区分大小写的最好方法比较,这样?

在它运行快速的SQL Server上 同样的查询EX pression可以一起使用LINQ到对象,以获得相同的结果

使用

  a.ToLowerInvariant()== b.ToLowerInvariant()
 
LINQ to SQL 数据库与LINQ对象的关系

至少得到了相同的结果,但它并没有得到SQL服务器上,据我所知道的处理,因此可以慢很多。

  A == b
 

解决方案

我不是在LINQ to SQL方面的专家,但你之前容比较可以只使用字符串的ToUpperInvariant()方法。

see also Differences between LINQ to Objects and LINQ to SQL queries

We are using the some queries over our database and our in memory objects.

What is the best way of doing an insensitive string compare with linq-to-sql so that?

It runs fast on SQL Server The same query expression can be used with linq-to-objects to get the same result

Using

a.ToLowerInvariant() == b.ToLowerInvariant()

at least gets the same results, but it does not get processed on SQL server as far as I can tell, so can be a lot slower then

a == b

解决方案

I'm not an expert in linq to sql, but you could just use the ToUpperInvariant() method of string before compareing.