多列不区分大小写的组

编程入门 行业动态 更新时间:2024-10-25 23:29:08
本文介绍了多列不区分大小写的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

无论如何,有没有做类似的事情的LINQ2SQL查询:

Is there anyway to do a LINQ2SQL query doing something similar to this:

var result = source.GroupBy(a => new { a.Column1, a.Column2 });

var result = from s in source group s by new { s.Column1, s.Column2 } into c select new { Column1 = c.Key.Column1, Column2 = c.Key.Column2 };

但是忽略分组列内容的大小写吗?

but with ignoring the case of the contents of the grouped columns?

推荐答案

您可以将StringComparer.InvariantCultureIgnoreCase传递给GroupBy扩展方法.

You can pass StringComparer.InvariantCultureIgnoreCase to the GroupBy extension method.

var result = source.GroupBy(a => new { a.Column1, a.Column2 }, StringComparer.InvariantCultureIgnoreCase);

或者您也可以按照 Hamlet Hakobyan 的建议在每个字段上使用ToUpperInvariant.我建议使用ToUpperInvariant或ToUpper而不是ToLower或ToLowerInvariant,因为它已针对程序比较进行了优化.

Or you can use ToUpperInvariant on each field as suggested by Hamlet Hakobyan on comment. I recommend ToUpperInvariant or ToUpper rather than ToLower or ToLowerInvariant because it is optimized for programmatic comparison purpose.

更多推荐

多列不区分大小写的组

本文发布于:2023-10-17 10:50:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小写   多列不

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!