fluid-nhibernate 映射 HasOne?参考?

发布于 2024-10-14 00:47:09 字数 1486 浏览 0 评论 0原文

不知道我应该如何映射它。我有两个表

Week 与列

Id、SeasionId、WeekStarts、MatchOfTheWeek

Matches 与列

Id、Location、MatchDate、Rounds

我的 Weeks 类有一个类型为 Match

    public virtual Match MatchOfTheWeek
    {
        get;
        set;
    }

Now I 的对象在我的比赛

    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

我在这里做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2024-10-21 00:47:09

我想你可能想使用:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文