Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 取消映射继承的MongoDB类成员_C#_Mongodb_Sitecore - Fatal编程技术网

C# 取消映射继承的MongoDB类成员

C# 取消映射继承的MongoDB类成员,c#,mongodb,sitecore,C#,Mongodb,Sitecore,我正在另一个API框架内将数据持久化到MongoDB。我使用的是MongoDB C#驱动程序,MongoDB.driver版本1.10.0.62。我的业务对象进入MongoDB的模型是: public class CommentEntity : EntityIdentity { [BsonId(IdGenerator = typeof(GuidGenerator))] public Guid CommentId { get; set;

我正在另一个API框架内将数据持久化到MongoDB。我使用的是MongoDB C#驱动程序,MongoDB.driver版本1.10.0.62。我的业务对象进入MongoDB的模型是:

public class CommentEntity : EntityIdentity
{
    [BsonId(IdGenerator = typeof(GuidGenerator))]
    public Guid CommentId
    {
        get;
        set;
    }

    public string FullName
    {
        get;
        set;
    }

    public string Message
    {
        get;
        set;
    }
}
在这种情况下,
EntityIdentity
是一个抽象类,由于我使用的框架,
EntityIdentity
碰巧已经有一个
Id
属性,所以我必须从中继承。由于Mongo默认使用
Id
作为其主要标识符,因此我已经用
[BsonId]
注释了
CommentId
。Mongo仍然试图从继承的抽象类中提取
Id
,因此我尝试如下方式取消映射:

BsonClassMap.RegisterClassMap<CommentEntity>(comment =>
{
    comment.AutoMap();
    comment.UnmapMember(c => c.Id);
});
BsonClassMap.RegisterClassMap(注释=>
{
comment.AutoMap();
comment.UnmapMember(c=>c.Id);
});
我得到的错误表明Mongo无法取消映射继承的成员:

memberInfo参数必须用于类CommentEntity,但用于类EntityIdentity

我怎样才能做到这一点


对于完整的上下文,我正在使用
Sitecore.Services.Client
Sitecore.Services.Core
作为我的API框架。

您是否尝试覆盖
CommentEntity
中的Id属性?是否尝试覆盖
CommentEntity
中的Id属性?