异常? HasManyToMany NHibernate 映射

发布于 2024-09-08 22:52:30 字数 1150 浏览 2 评论 0原文

数据库结构:

Shows
ID
Name

Genres
ID
Name

ShowsGenres
ShowsID
GenresID

上面是我的数据库,我正在尝试找出如何正确映射它。我的 Show 对象是这样的:

public class Show
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Genre> Genres { get; set; }
}

我的 Genre 对象是:

public class Genre
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Show> Shows { get; set; }
}

我尝试了 HasManyToMany 的几种不同变体,但没有一个按照我想要的方式工作。

我需要能够删除节目以及与流派或多个流派的关系,但不能删除流派。

我需要能够删除某个类型及其与一个或多个节目的关系,但不能删除这些节目。

我该如何映射这个或者我需要尝试不同的东西?

更新:还要更多地考虑它,我还需要能够消除节目和流派之间的关系,而不删除节目或流派。

这是我的映射,但不确定它们是否正确。

        HasManyToMany<Genre>(x => x.Genres)
            .Table("ShowGenres")
            .ParentKeyColumn("ShowID")
            .ChildKeyColumn("GenreID");

        HasManyToMany<Show>(x => x.Shows)
            .Table("ShowGenres")
            .ParentKeyColumn("GenreID")
            .ChildKeyColumn("ShowID");

Database Strucutre:

Shows
ID
Name

Genres
ID
Name

ShowsGenres
ShowsID
GenresID

Above is my Database I am trying to figure out how to map this properly. My Show object is like this:

public class Show
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Genre> Genres { get; set; }
}

My Genre Object is:

public class Genre
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<Show> Shows { get; set; }
}

I have tried several different varations of HasManyToMany, but none work the way I want them to.

I need to be able to delete a show and the relationship with the genre, or many genres, but not delete the genre(s).

I need to be able to delete a genre and its relationship with a show, or many shows, but not delete the show(s).

How can I map this or do I need to try something differently?

Update: Also thinking about it more I would also need to be able to remove the relationship between a show and a genre without removing the show or the genre.

Here are my mappings I have, but not exactly sure they are correct.

        HasManyToMany<Genre>(x => x.Genres)
            .Table("ShowGenres")
            .ParentKeyColumn("ShowID")
            .ChildKeyColumn("GenreID");

        HasManyToMany<Show>(x => x.Shows)
            .Table("ShowGenres")
            .ParentKeyColumn("GenreID")
            .ChildKeyColumn("ShowID");

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

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

发布评论

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

评论(1

独行侠 2024-09-15 22:52:30

这是一篇旧帖子,但我基本上有同样的问题。在这里回答:

HasManyToMany Fluent NHibernate 映射删除错误

This is an old post but I basically had the same question. Answered here:

HasManyToMany Fluent NHibernate Mapping Delete Error

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