MongoDb C# driver 2.4 - LINQ with dynamic GroupBy not supported -


var result = await events.asqueryable()             .where(_ => _.date >= from.date && _.date <= to.date)             .groupby(_ => _.someprop)             .select(n => new { n.key, count = n.count() })             .tolistasync(); 

works charm. lets want aggregate custom field - received in aggregateby string parameter. try:

var propertytogroupby = typeof(diagnosticevent).getproperties()                         .first(x => x.name.tolowerinvariant() == aggregateby); 

and then:

var result = await events.asqueryable()             .where(_ => _.date >= from.date && _.date <= to.date)             .groupby(p => propertytogroupby.getvalue(p))             .select(n => new { n.key, count = n.count() })             .tolistasync(); 

which ends in:

getvalue of type system.reflection.propertyinfo not supported in expression tree system.string type.getvalue({document})

any idea how while sticking linq? know can use fluent api with:

var group = new bsondocument { { "_id", $"${aggregateby}"}, { "count", new bsondocument("$sum", 1) } }; 

but want consistent linq approach.

full stack trace: https://pastebin.com/rnzxi1kj


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -