Horje
save and query mongodb collection as dynamic ExpandoObject Code Example
save and query mongodb collection as dynamic ExpandoObject
QUESTION:
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;
}


ANSWER:
You can use the string-based syntax, since the expression doesn't offer any advantages with dynamic anyway:
  
var cursor = db.GetCollection<dynamic>("foo").
                Find(Builders<dynamic>.Filter.Eq("_id", someId));

or

var cursor = db.GetCollection<ExpandoObject>("foo").
                Find(Builders<ExpandoObject>.Filter.Eq("_id", someId));




Csharp

Related
générer un nombre aléatoire en c# Code Example générer un nombre aléatoire en c# Code Example
c# list contains null Code Example c# list contains null Code Example
c# programiticall change selected index of databound datagridviewcombo box Code Example c# programiticall change selected index of databound datagridviewcombo box Code Example
c# check file similarities Code Example c# check file similarities Code Example
asp.net unregister client script Code Example asp.net unregister client script Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9