MongoDB c# driver - Can a field called Id not be Id?

前端 未结 1 1275
陌清茗
陌清茗 2021-01-19 02:42

More particulary, there is a class

class X {
       ....
       string Id { get; set; }
}

class Y : X {
       ObjectId MyId { get; set; }
}
相关标签:
1条回答
  • 2021-01-19 03:06

    The answer to your question is "yes, but...".

    It is possible to have a member called Id which is not mapped to the _id element. For example:

    public class X {
        [BsonId]
        public ObjectId MyId;
    }
    
    public class Y : X {
        public string Id;
    }
    

    However, in a class hierarchy the _id member must be at the root of the hierarchy (in other words, all members of the hierarchy must agree on using the same _id).

    0 讨论(0)
提交回复
热议问题