任何人都可以帮助我为什么我的onetoone属性不会加载?我有另一个项目,他们工作正常,但由于某种原因,在我的两个属性都没有。
映射:
public class PlayerMap : ClassMap<Player>
{
public PlayerMap()
{
Table("Player");
LazyLoad();
Id(x => x.PlayerId).GeneratedBy.Identity().Column("PlayerId");
HasOne(x => x.Stats).ForeignKey("PlayerId");
HasOne(x => x.Rankings).ForeignKey("PlayerId");
Map(x => x.LastName).Column("LastName");
Map(x => x.FirstName).Column("FirstName");
HasMany(x => x.MatchResults).KeyColumn("PlayerId");
}
}
属性:
public virtual Stats Stats { get; set; }
public virtual Rankings Rankings { get; set; }
在数据库中,它们是使用外键关系设置的。
我哪里错了?
答案 0 :(得分:1)
This answer似乎是您正在寻找的东西。假设Player
被视为父级,而Stats
/ Rankings
是子级,则您的映射应如下所示:
//PlayerMap
HasOne(x => x.Stats).PropertyRef(r => r.Player).Cascade.All();
HasOne(x => x.Rankings).PropertyRef(r => r.Player).Cascade.All();
//StatsMap
References(x => x.Player, "PlayerId").Not.Nullable();
//RankingsMap
References(x => x.Player, "PlayerId").Not.Nullable();