Case insensitive group on multiple columns

前端 未结 4 795
Happy的楠姐
Happy的楠姐 2021-01-17 10:14

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

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

4条回答
  •  隐瞒了意图╮
    2021-01-17 10:40

    I had the same issue grouping by the values of DataRow objects from a Table, but I just used .ToString() on the DataRow object to get past the compiler issue, e.g.

    MyTable.AsEnumerable().GroupBy(
        dataRow => dataRow["Value"].ToString(),
        StringComparer.InvariantCultureIgnoreCase)
    

    instead of

    MyTable.AsEnumerable().GroupBy(
        dataRow => dataRow["Value"],
        StringComparer.InvariantCultureIgnoreCase)
    

提交回复
热议问题