Skip to content

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

Merged
microsoft-github-policy-service[bot] merged 12 commits intomasterfrom
users/leminh/groupbyLinqMultiKey
Nov 25, 2024
Merged

Query: Adds LINQ support for Multi-key Group By translation#4857
microsoft-github-policy-service[bot] merged 12 commits intomasterfrom
users/leminh/groupbyLinqMultiKey

Conversation

@leminh98
Copy link
Copy Markdown
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

Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs Outdated
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs Outdated
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs Outdated
@adityasa
Copy link
Copy Markdown
Contributor

adityasa commented Nov 22, 2024

        bool ignoreOrderingForAnonymousTypeObject = false,

Please rename to just ignoreOrder #Closed


Refers to: Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqTestsCommon.cs:686 in 7c8ff08. [](commit_id = 7c8ff08, deletion_comment = False)

@leminh98 leminh98 added the auto-merge Enables automation to merge PRs label Nov 22, 2024
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs Outdated
Comment thread Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs Outdated
adityasa
adityasa previously approved these changes Nov 24, 2024
Copy link
Copy Markdown
Contributor

@adityasa adityasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@next-phil
Copy link
Copy Markdown

Does this document need updating to mention Group By being available now?

https://learn.microsoft.com/en-us/cosmos-db/query/linq-to-sql#supported-linq-operators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Enables automation to merge PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants