Timeline for answer to How to group by multiple columns using LINQ by leppie
Current License: CC BY-SA 2.5
Post Revisions
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 1, 2025 at 6:13 | comment | added | Douglas Kersey | If you’re new to using anonymous types in group operations, the new keyword is what enables the grouping logic in this example. | |
| Oct 29, 2024 at 20:38 | comment | added | TylerH | This answer would benefit from a more thorough code example. It's entirely unclear how one is supposed to use the code fragment as currently provided. | |
| May 2, 2023 at 17:56 | comment | added | NetMage | @ByronCarasco Though that doesn't really matter since LINQ to databases translates to SQL (or a database query language) anyway. | |
| Jan 14, 2022 at 10:59 | comment | added | david | It work with core2.2, but it's broken since DotNetCore5. What is the new version ? | |
| Jan 24, 2018 at 12:05 | comment | added | Damith | I just want to know whether group by multiple column be affected to performance issue? I faced an issue after applied group by with 4 columns. Query returns around 5000 records which contains some duplicate values. | |
| Dec 11, 2017 at 0:56 | comment | added | Simon Dowdeswell | if you want a particular type (ie new Ttt { x.Column1, x.Column2 } ) use a struct to get equals as comparing the constituent parts - a class will by default compare the references which is probably not what you want since each instance will have a different reference | |
| Oct 9, 2017 at 16:58 | comment | added | leppie | @Jacques yes, but gets translated properly, eg in EF/Linq2Sql. | |
| Oct 9, 2017 at 15:04 | comment | added | Jacques | A bit tough to visualize the output data structure when you're new to Linq. Does this create a grouping where the anonymous type is used as the key? | |
| Sep 7, 2017 at 18:57 | comment | added | Byron Carasco | @HoGo anonymous typed objects implement their own Equals and GetHashCode methods which is used when grouping the objects. | |
| Jan 19, 2016 at 7:57 | comment | added | HoGo | I thought in this case the new objects would by compared by reference, so no match - no groupping. | |
| Dec 7, 2015 at 10:23 | comment | added | Milan | in case of mvc with nHibernate getting error for dll issues. Problem resolved by GroupBy(x=> new { x.Column1, x.Column2 }, (key, group) => new { Key1 = key.Column1, Key2 = key.Column2 , Result = group.ToList() }); | |
| Aug 6, 2013 at 15:41 | comment | added | Chris | If you're new to grouping with anonymous types the use of the 'new' keyword in this example does the magic. | |
| Jul 18, 2011 at 13:57 | review | Suggested edits | |||
| Jul 18, 2011 at 14:30 | |||||
| May 11, 2009 at 9:55 | vote | accept | Sreedhar | ||
| May 11, 2009 at 7:37 | history | answered | leppie | CC BY-SA 2.5 |