8

I'm trying to get a private backing field mapped in MongoDB.
My model looks like:

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(); }
    }
}

I'm basically trying to map _competitorBests, to be CompetitorBests (which exists in my document in mongo)

Note: This model is shared by NHibernate (hence the virtual)
I can't see anything obvious in the docs.

How do I do it?

4

1 に答える 1

12

This did the trick:

BsonClassMap.RegisterClassMap<Competitor>(cm =>
{
    cm.AutoMap();
    cm.MapField("_competitorBests").SetElementName("CompetitorBests");
});
于 2012-07-04T15:25:55.740 に答える