FluentNHibernate映射

时间:2011-05-14 14:17:25

标签: c# asp.net nhibernate fluent-nhibernate mapping

我有同样的课程:

public class Card : EntityBase
{
    private IList<Accident> accidents;
    public Card()
    {
        Accidents = new List<Accident>();
    }

    public virtual IList<Accident> Accidents
    {
        get { return accidents; }
        set { value = accidents; }
    }

    public virtual void AddAccident(Accident accident)
    {
        Accidents.Add(accident);
        accident.Card = this;
    }

}

public class Accident : EntityBase
{
    public Accident(){ 
    }
    public virtual Card Card { get; set; }     

}

他们的映射

public class AccidentMap : ClassMap<Accident>
{
    public AccidentMap()
    {
        Table("ACCIDENT");
        Id(x => x.Id).Not.Nullable().Column("ID_ACCIDENT");
        References(x => x.Card).Column("ID_CARD").Cascade.SaveUpdate();
    }
}

当我试图保存事故时,我在Accidents.Add(意外)中有NullReferenceException。为什么? 感谢。

1 个答案:

答案 0 :(得分:1)

set { value = accidents; } 应该 set { accidents = value; }