Case insensitive group on multiple columns
c#, linq, linq-to-sql
Solution
You can pass `StringComparer.InvariantCultureIgnoreCase` to the `GroupBy` extension method.
var result = source.GroupBy(a => new { a.Column1, a.Column2 },
StringComparer.InvariantCultureIgnoreCase);
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.
Problem
Is there anyway to do a LINQ2SQL query doing something similar to this: ``` var result = source.GroupBy(a => new { a.Column1, a.Column2 }); ``` or ``` 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?