var fs = this.backend.DigitalInputs.GroupBy(di => di.Channel).Select(g => new { Channel = g.Key, Count = g.Count() });
QueryModel ->
* MainFromClause: {from IGrouping`2 g in {value(Backend.Implementations.Lest.Linq.LivingQueryable`1[Backend.Domain.DigitalInput]) => GroupBy([di].Channel, [di])}}
* FromExpression: {{value(Backend.Implementations.Lest.Linq.LivingQueryable`1[Backend.Domain.DigitalInput]) => GroupBy([di].Channel, [di])}}
* QueryModel:
* MainFromClause: {from DigitalInput di in value(Backend.Implementations.Lest.Linq.LivingQueryable`1[Backend.Domain.DigitalInput])}
* ResultOperators: (1) -> {GroupBy([di].Channel, [di])}
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel){
// do nothing base.VisitMainFromClause(fromClause, queryModel);}
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
{
LQL.Expressions.Catalog.LQLEntityExpression entity = fromClause.ItemType.GetDomainEntity();
this.lqlQueryModel.Search = entity;
}
Hi,
My LINQ queries can get super-complex, so in order to solve this I ended up writing a recursive parsing system. So my query visitor would call an expression parser to parse an expression, and then the expression would be a SubQueryExpression, which would trigger a call back into the QueryModel.
Now, for the group by operator – it is a ResultOperator – just like “Count()”, or “Sum()”. The difference is that it is a sequence ResultOperator. So I added extra code to deal with a type of result operator that was a sequence rather than just a single value.
I hope this helps. You are more than welcome to look at my code, but my application is so specific. Trying to translate LINQ to procedural C++ in this conext means the final result strongly influenced the architecture I used (also, when I started this I was “hacking” and didn’t know what I was doing, so probably made some important decision without realizing it).
The top level query processor. Note the code for parsing the result operators: https://github.com/gordonwatts/LINQtoROOT/blob/master/LINQToTTree/LINQToTTreeLib/QueryVisitors/QueryVisitor.cs#L69 (in particular the bit about a sequence result operator).
The group by result operator: https://github.com/gordonwatts/LINQtoROOT/blob/master/LINQToTTree/LINQToTTreeLib/ResultOperators/ROGroup.cs#L49
It may well be understanding my code is more effort than just forging ahead with some test cases in your environment. 😉
Cheers,
Gordon