if (_operationType.Equals(ReportAggregationOperation.Sum))
{
return query
.GroupBy(g => new
{
Day = TestableDbFunctions.TruncateTime(groupBy.Invoke(g))
})
.Select(x => new
{
Key = x.Key.Day.Value.ToString("yyyyMMdd"),
Value = (int?) x.Sum(operationProperty.Compile()),
}).ToDictionary(t => t.Key, t => t.Value);
}
else
{
return query
.GroupBy(g => new
{
Day = DbFunctions.TruncateTime(groupBy.Invoke(g))
})
.Select(
x => new
{
Key = x.Key.Day.ToString("yyyyMMdd"),
Value = (int?) x.Average(operationProperty.Compile()),
}).ToDictionary(t => t.Key, t => t.Value);
}
I'm using an IOC container for creating instances like dailyaggreagtor/monthlyaggregator... But I wasn't able to build this group by expression, or to apply the right design pattern to eliminate the above if statement.
Aucun commentaire:
Enregistrer un commentaire