Inheritance in MongoDb: how to request instances of defined type

后端 未结 5 1931
迷失自我
迷失自我 2021-02-10 16:34

This is how I used to utilize inheritance in Entity Framework (POCO):

ctx.Animals // base class instances (all instances)
ctx.Animals.OfType  // inher         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-10 17:19

    If the only concern is hardcoding class name, you can do something like this:

    collection = db.GetCollection("Animals");
    var query = Query.EQ("_t", typeof(Cat).Name);
    var cursor = collection.Find(query);
    

提交回复
热议问题