Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Adds LINQ support for Multi-key Group By translation #4857

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

leminh98
Copy link
Contributor

@leminh98 leminh98 commented Oct 28, 2024

Pull Request Template

Description

This PR features the new syntax for multi-key group by queries, allowing for grouping of multiple properties.

Full syntax:

// Function Signature
public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey,TElement>> GroupBy<TSource,TKey,TElement> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TKey> keySelector, Func<TSource,TElement> elementSelector);

// Usage
Enumerables.GroupBy( groupByKeys => keySelectiorLambda, (keys, values) => valueSelectorLambda);

Example

  • Grouping by single keys and projecting single value
Enumerable.GroupBy( /*keySelector*/ k => k.Id,  /*valueSelector*/ (key, values) => values.Count());
  • Grouping by single keys and projecting multiple values
Enumerable.GroupBy( 
              /*keySelector*/ k => k.Id, 
              /*valueSelector*/ (key, values) => new
               {
                   idField = key.key1,
                   count = values.Count(),
               });
  • Grouping by multiple keys and projecting single value
Enumerable.GroupBy( 
              /*keySelector*/  k => new
                 {
                     key1 = k.Id,
                     key2 = k.Int
                 } , 
              /*valueSelector*/ (key, values) => values.Count());
  • Grouping by multiple keys and projecting multiple values
Enumerable.GroupBy(
/*keySelector*/
              k => new
                  {
                      key1 = k.Id,
                      key2 = k.Int
                  } , 
/*valueSelector*/
                (key, values) => new
                {
                    idField = key.key1,
                    count = values.Count(),
                })

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

closes ##1202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant