开发者

Unusual? HasManyToMany NHibernate Mapping

开发者 https://www.devze.com 2023-01-06 00:24 出处:网络
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:

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 v开发者_如何学Cirtual 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");


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

HasManyToMany Fluent NHibernate Mapping Delete Error

0

精彩评论

暂无评论...
验证码 换一张
取 消