FluentNHibernate 映射
我有相同的类:
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();
}
}
当我尝试保存 Accident 时,我在 Accidents.Add(accident) 中有 NullReferenceException。为什么? 谢谢。
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 accident)
{
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置{值=事故; }
应该是
set { 事故 = 值; }
set { value = accidents; }
Should be
set { accidents = value; }