Linq查询以选择不区分大小写的表中的不同行 [英] Linq query to select distinct rows from a table without case sensitive

查看:278
本文介绍了Linq查询以选择不区分大小写的表中的不同行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下动态Linq查询来选择不同的行:

I am using the following dynamic Linq query to select distinct rows:

var distinctValue = (from row in orgdt.AsEnumerable()
                                     select new { NAME = row.Field<string>("NAME")}).Distinct().ToList(); </string>



NAME是表的列-可能有两行,例如Empemp.
在列表2中显示了名称,但我的要求是仅显示一个.



NAME is column of the table - in that there may be two rows like Emp and emp.
In list 2 names are displayed, but my requirement is that only one should be displayed. How can this be done?

推荐答案

使用where子句.就像

Use a where clause. As in,

from row in orgdt.AsEnumerable()
where row.Field("NAME") == "Emp"


您必须更改为该列(或整个数据库)的排序规则以不区分大小写"或在代码中执行不同的操作.
You have to change to collation of that column (or the complete database) to "case insensitive" or perform the distinct operation in code.


Distinct()可以使用IEqualityComparer作为参数.提供一个不区分大小写的字符串比较.
Distinct() can take an IEqualityComparer as an argument. Provide one that does a case-insensitive string comparison.


这篇关于Linq查询以选择不区分大小写的表中的不同行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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