fluent-nhibernate映射HasOne?参考?

时间:2011-01-23 23:27:19

标签: nhibernate fluent-nhibernate mapping

不确定我应该如何映射这个。我有两张桌子

列周

Id,SeasionId,WeekStarts,MatchOfTheWeek

与列匹配

ID,位置,MatchDate,Rounds

my Weeks类有一个Match

类型的对象
    public virtual Match MatchOfTheWeek
    {
        get;
        set;
    }

现在我已经在我的匹配

上进行了映射
    public MatchMapping()
    {
        Id(x => x.Id);
        Map(x => x.Location);
        Map(x => x.Rounds);
        Map(x => x.MatchDate).Nullable();
        HasManyToMany(x => x.Boxers)
            .Table("Boxer_Match")
            .ParentKeyColumn("matchid")
            .ChildKeyColumn("boxerid")
            .AsSet()
            .Cascade.SaveUpdate();
        HasOne(x => x.Result)
            .Cascade.Delete();
    }

和我的周映射

    public WeekMapping()
    {
        Id(x => x.Id);
        References(x => x.Season);
        HasMany(x => x.Predictions).Cascade.SaveUpdate().Inverse();
        HasOne(x => x.MatchOfTheWeek).ForeignKey("MatchOfTheWeek");
        //References(x => x.MatchOfTheWeek).Nullable();
        HasManyToMany(x => x.Matches)
            .Table("WeekMatch")
            .ParentKeyColumn("WeekID")
            .ChildKeyColumn("MatchId")
            .AsSet()
            .Cascade.All();
        Map(x => x.WeekStarts);
    }

基本上,由于周长显示出现错误。如果我换掉HasOne以用引用的注释行替换它。然后它不会出错但返回null

我在这里做错了什么?

1 个答案:

答案 0 :(得分:3)

我想你可能想用:

References(x => x.MatchOfTheWeek).Nullable().Column("MatchOfTheWeek");

如果我错了,请纠正我,但我认为它会尝试使用默认约定列MatchOfTheWeek_id