[CSHARP-4369] Incorrect translation of Group/Where/Select in LINQ3 Created: 16/Oct/22  Updated: 28/Oct/23  Resolved: 29/Oct/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.18.0
Fix Version/s: 2.19.0

Type: Bug Priority: Unknown
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-4244 Support object comparison at root lev... Closed
is depended on by CSHARP-4331 Make LINQ3 the default LinqProvider Closed
is depended on by CSHARP-4358 Update tests that only test against L... Closed
Backwards Compatibility: Fully Compatible

 Description   

The test named `States_with_pops_over_20000_queryable_syntax` fails when run using LINQ3.

The query is:

var queryable =
    from z in collection.AsQueryable()
    group z by z.State into g
    where g.Sum(x => x.Population) > 20000
    select new { State = g.Key, TotalPopulation = g.Sum(x => x.Population) };

The translation produced by LINQ3 is:

Tests10151703.testcollection.Aggregate([
    { "$group" : { "_id" : "$state", "__agg0" : { "$sum" : "$pop" } } },
    { "$match" : { "$expr" : { "$gt" : [{ "$sum" : "$_elements.pop" }, 20000] } } },
    { "$project" : { "State" : "$_id", "TotalPopulation" : "$__agg0", "_id" : 0 } }
])

but it should be:

Tests10151703.testcollection.Aggregate([
    { "$group" : { "_id" : "$state", "__agg0" : { "$sum" : "$pop" } } },
    { "$match" : { "_agg0" : { "$gt" : 20000 } } },
    { "$project" : { "State" : "$_id", "TotalPopulation" : "$__agg0", "_id" : 0 } }
])

 
 



 Comments   
Comment by Githook User [ 29/Oct/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4369: Translate Group/Where/Select correctly in LINQ3.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/b75267ad0b50d84ceab49934f3f87deaf9d1c079

Generated at Wed Feb 07 21:48:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.