문제

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?

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top