1
votes

Not sure how I should map this. I have two tables

Week with the columns

Id, SeasionId, WeekStarts, MatchOfTheWeek

Matches with the columns

Id, Location, MatchDate, Rounds

my Weeks classhas a object of type Match

    public virtual Match MatchOfTheWeek
    {
        get;
        set;
    }

Now I have mapping on my Match

    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();
    }

and my Week mappings

    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);
    }

Bascially As the Weekmapping is shown there it errors. If i swap out the HasOne to replace it with the commented line which is a Reference. then it doesn't error but returns a null

What have i done wrong here?

1

1 Answers

3
votes

I think you'd probably want to use:

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

Correct me if I'm wrong, but I think it would be trying to use the column MatchOfTheWeek_id using the default conventions.