本文介绍了多列不区分大小写的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论如何,有没有做类似的事情的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.
更多推荐
多列不区分大小写的组
发布评论