views:

50

answers:

0

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