Hi ,
I have a use case where my idselector expression and Group Expression are generated at run time. but i am unable to use them. below is the code
db.GetCollection<BsonDocument>("CollectionName")
.Aggregate()
.Group(Bakerc178f660479a4db4ba176dc62b7ec21c.idfunc, Bakerc178f660479a4db4ba176dc62b7ec21c.func).ToListAsync()
Below is the dynamically generated Expression funcs
public static class Bakerc178f660479a4db4ba176dc62b7ec21c{
public static readonly Expression<Func<IGrouping<dynamic, BsonDocument>, dynamic>> func = key => new {MyKey= key.Key };
public static readonly Expression<Func<BsonDocument, dynamic>> idfunc = key =>new { Year=(double)key["Year"]} ;
}
On Executing i get following error
{"Value type of serializer is <>f__AnonymousType1`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] and does not match member type System.Object.\r\nParameter name: serializer"}
Please note that above works if i put those funcs directly in groupby and idselector as following
db.GetCollection<BsonDocument>("CollectionName")
.Aggregate()
.Group(key => new { Year = (double)key["Year"] }, key => new { MyKey = key.Key }).ToListAsync();
but i can't use this as my expressions are generated dynamically. Let me know how to handle this.
Many Thanks
Ravinder Singh