开发者

FluentNHibernate Mapping

I have same classes:

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 ac开发者_如何学运维cident)
    {
        Accidents.Add(accident);
        accident.Card = this;
    }

}

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

}

And their mappings

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

When I trying to save Accident I have NullReferenceException in Accidents.Add(accident). Why? Thanks.


set { value = accidents; } Should be set { accidents = value; }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜