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

烈酒焚心 提交于 2019-12-01 18:18:52

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!