C# 取消映射继承的MongoDB类成员
我正在另一个API框架内将数据持久化到MongoDB。我使用的是MongoDB C#驱动程序,MongoDB.driver版本1.10.0.62。我的业务对象进入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;
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属性?