映射的私人支持字段与MongoDB的C# [英] Mapping a private backing field with MongoDB C#

查看:223
本文介绍了映射的私人支持字段与MongoDB的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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



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

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

注意::该模型是由NHibernate的(共享因此虚拟)结果
我看不到任何东西在文档显而易见的。

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

我该怎么办呢?

推荐答案

这做的伎俩:

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

这篇关于映射的私人支持字段与MongoDB的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆