With the legacy Linq driver we use constructs such as below:
.GroupBy(s => new
{
TimeContainer = statisticsRequest.AggregateTime ? (DateTime?)null : s.TimeContainer,
PublisherId = statisticsRequest.AggregatePublishers ? (Guid?)null : s.PublisherId,
BuyerId = statisticsRequest.AggregateBuyers ? (Guid?)null : s.BuyerId,
})
.Select(s => new CombinedStats()
{
From = s.Min(x => x.TimeContainer),
To = s.Max(x => x.TimeContainer),
PublisherId = s.Key.PublisherId,
BuyerId = s.Key.BuyerId,
Request = new RequestStats()
{
BuyerRequests = s.Sum(x => x.Requests),
However, with https://jira.mongodb.org/browse/CSHARP-1771, building a dynamic GroupBy seems to break (giving an IIF error).
I haven’t found a way to build a dynamic group by without massive rewrites. Does anyone know of a solution to this?