使用MongoDB C#映射私有支持字段

Ale*_*lex 4 c# mongodb mongodb-.net-driver

我正在尝试在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(); }
    }
}
Run Code Online (Sandbox Code Playgroud)

我基本上试图将_competitorBests映射为CompetitorBests(存在于我的mongo文档中)

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

我该怎么做?

Ale*_*lex 10

这样就可以了:

BsonClassMap.RegisterClassMap<Competitor>(cm =>
{
    cm.AutoMap();
    cm.MapField("_competitorBests").SetElementName("CompetitorBests");
});
Run Code Online (Sandbox Code Playgroud)

  • 你能在.CompetitorBests属性上运行linq查询吗?它为我吹嘘. (3认同)