jeudi 2 août 2018

Properties inside generic class. get property in Find of Mongodb

I am using this class:

public class MyClass 
{
    ...
    public string culture { get; set; }
    ...
}

and this function:

object getData<T>() 
{
   var res = GetCollection<T>().Find(x => x.culture == "ca-ES").ToList()

   return res;
}

calling it as getData<MyClass>()

GetCollection function is but it is working, then it is not the problem:

private IMongoCollection<T> GetCollection<T>()
{
    db.GetCollection<T>("myclass");
}

My problem is that the function I am using inside find a comparison to get that rss by culture. The compiler give me an error. That property is inside other classes with the same name.

Json of myclass in mongo is:

[
    {
      "culture": "ca-ES", ...
    },
    {
      "culture": "es-ES", ...
    },
    {
      "culture": "en-GB", ...
    }
]

In the example should return:

{
    "culture": "ca-ES", ...
}

How can I resolve it to compare by culture?





Aucun commentaire:

Enregistrer un commentaire