映射的私人支持字段与MongoDB的C#(Mapping a private backing fie

2019-06-26 01:03发布

我试图让MongoDB中映射的私人支持字段。
我的模型是这样的:

public class Competitor
{
    private IList<CompetitorBest> _competitorBests;

    public virtual int CompetitorId { get; set; }

    public virtual string Name
    {
        get
        {
            if (Type == "Team")
                return TeamName;

            return FirstName + " " + LastName;
        }
    }

    public virtual IEnumerable<CompetitorBest> CompetitorBests
    {
        get { return _competitorBests.ToArray(); }
    }
}

基本上,我试图映射_competitorBests,是CompetitorBests(它存在我的蒙戈文件中)

注意:此模型由NHibernate的共享(因此virtual
我看不到任何东西在文档中明显。

我该怎么做?

Answer 1:

这确实的伎俩:

BsonClassMap.RegisterClassMap<Competitor>(cm =>
{
    cm.AutoMap();
    cm.MapField("_competitorBests").SetElementName("CompetitorBests");
});


文章来源: Mapping a private backing field with MongoDB C#