Reputation: 7442
Can anyone help as to why my onetoone properties won't load? I have another project where they work fine, but for some reason in this one neither of my two properties will work.
Mapping:
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");
}
}
Properties:
public virtual Stats Stats { get; set; }
public virtual Rankings Rankings { get; set; }
In the database, they are setup with a Foreign Key relationship.
Where am I going wrong?
Upvotes: 0
Views: 117
Reputation: 1814
This answer seems to be what you're looking for. Assuming Player
is considered the parent and Stats
/Rankings
are the children, your mapping should look something like this:
//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();
Upvotes: 1