与不区分大小写字符串比较LINQ到SQL和LINQ到对象 [英] Case insensitive string compare with linq-to-sql and linq-to-objects

查看:210
本文介绍了与不区分大小写字符串比较LINQ到SQL和LINQ到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

又见<一href="http://stackoverflow.com/questions/1718195/differences-between-linq-to-objects-and-linq-to-sql-queries">Differences LINQ之间的对象和LINQ to SQL查询

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

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

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

使用

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

至少得到了相同的结果,但它并没有得到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.

这篇关于与不区分大小写字符串比较LINQ到SQL和LINQ到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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