I'm saving a dynamic
object in my database but I would also like to retrieve it as a dynamic object. How can this be done? I tried it like so:
public dynamic GetItemById(ObjectId id)
{
dynamic result = Db.GetCollection<dynamic>("Items").Find(x => x.Id == id).FirstOrDefaultAsync().Result;
return result;
}
But this gives me the following error:
CS1963 An expression tree may not contain a dynamic operation
I know this can be fixed by using a typed object instead of a dynamic one. But I don't want to use any typed objects, because that kind of defeats the entire purpose of using a NoSQL database like MongoDB (or at least, imho).
How can I query my collections by Id
or any other property for that matter using dynamic
objects?