Map Reference Table with NHibernate
Posted on 2009-05-05
I'm trying to map out some classes to use with NHibernate. I have most things correct, however, I'm trying to map a reference table for Directors for movies.
We have a few tables in the database, one being a Movies table that holds details about a particular movie. Another table a Directors table that holds details pertaining to movie directors. The problem is many directors can direct one movie, and one director can direct multiple movies. So we created a reference table to show this:
MovieId | DirectorId
This way we can pull up all movies directed by a director and also list all directors for a particular movie.
How can I map this in NHibernate so that when I reference my Movie object I have a collection of directors for that movie, if any, and when I access my Director object, I have a collection of movies directed by him/her, if any?
Movie movie = new Movie();
movie.Directors (type of IList<Directors>) or something to that extent.
Director director = new Director();
director.Movies (same as above IList<Movie>)