in the first version you are creating an anonymous type with a single property named
groupkey. anonymous types in c# use structural equality so the equality of the values comes down to the equality of the keys. this causes them to be properly grouped together.
in the second case you are using a custom type named
groupingkey. it appears this uses the default or referential equality. hence none of the instances are considered equal and hence they get put into different groups.
- Why does using anonymous type work and using an explicit type not in a GroupBy?
- When using "yield" why does compiler-generated type implement both IEnumerable and IEnumerator
- Why not reveal the type and identity of the source to the client?
- Why Skip and Take does not work when passing through a method?
- Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?
- Why does the Linq Cast<> helper not work with the implicit cast operator?
- Why does this combination of Select, Where and GroupBy cause an exception?
- Why does Linq not have Head and Tail?
- LINQ: why does this query not work on an ArrayList?
- Linq WHERE EF.Functions.Like - Why direct properties work and reflection does not?
- Why Linq Prepend() does not work with List<T>?
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- Why does .Equals not work in this LINQ example?
- Linq - Using GroupBy with my own type vs anonymous type
- How do I get property names of a type using a lambda expression and anonymous type?
- 'IEnumerable<>' does not contain a definition for '' and no extension method '' accepting a first argument of type 'IEnumerable<>' could be found
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- Why does the StringComparison.InvariantCultureIgnoreCase not work with this Db4o linq query?
- Why does LINQ not work to add DataRows to a DataTable?
- Why does DbFunctions not work with Linq to Entities
- Why does using Linq's .Select() return IEnumerable<dynamic> even though the type is clearly defined?
- Why orderBy does not work for this linq expression?
- WHERE statement does not work in unit test using It.IsAny
- Querying XML with LINQ and using null in place of a particular xml attribute if it does not exist
- why doesn't .Except() and Intersect() work here using LINQ?
- CS1061: 'IEnumerable<>' does not contain a definition for '' and no extension method '' accepting a first argument of type 'IEnumerable<>'
- Why does Linq join on Nullable<T> not work the same as ==?
- Why does this filter work on a List<T> but not on an IQueryable<T>?
- int' does not contain a definition for 'contains' and no extension method 'contains' accepting a first argument of type 'int' could be found
- Why does this work and this doesn't?
More Query from same tag
- Sorting Datatable with linq with correct datatype of a column
- Linq to SQL: Combining objects through a summation of one field only
- Populate a Datagrid with a Linq query
- Not disposed items in linq query
- Try to achieve EXIST in Linq, but Any() in where clause for Nested Query takes forever to process
- How to assign List<Bear> or List<Goat> to List<IAnimal>
- Optimising foreach loops
- How to construct a specific linq query?
- Linq Query sub-selection issue
- LINQ Query IList<string> to JSon Format
- Grouping using LINQ
- DateTime accumalator LINQ function
- Entity Framework Get Table By Name
- Merge Date Ranges Linq to SQL
- Linq, Entity Framework and WCF
- Linq select Item where it is equal to ID in another table
- DbIsNullExpression exception in linq to EF4 query
- LINQ Select and Where not correctly returning any results?
- Linq with join need distinct rows by ID
- Nested Linq crashes intellisense
- Can't convert stored procedure to Linq expression successfully
- WCF to Database Connectivity
- Adding List<t>.add() another list
- Union 2 lists with additional content change for ID that occurs in both source lists
- Entity Framework + DayOfWeek
- How to add a conditional statement within an Enumerable method?
- Entity Framework filter on inner list
- Remove an element from list inside a list in C#.
- How to handle no matches case in List.First in c#?
- Inner join on 2 arrays?