[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Map Reference Table with NHibernate

Posted on 2009-05-05
4
Medium Priority
?
1,082 Views
Last Modified: 2012-05-06
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
----------------------
      1             2
      2             2
      3             2
      1             4
      5             7

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?

Such as:

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

Thanks.
0
Comment
Question by:Phreak3eb
4 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 24310151
Create an association from Movie Table  ID to ReferenceTable.MovieID
Create an association from Director Table ID to Reference Table DirectorID

This is how you do it using dbml and Linq not sure if NHibernate is the same.

When the association is done you should be able to access Movie.MovieDirectors

... Does NHibernate support 'Associations'?  (Right click)
0
 
LVL 9

Expert Comment

by:tculler
ID: 24310498
I cannot offer a solution to your problem because I'm not familiar with NHibernate, but I do find it necessary to say that the table you are working with here is not a "reference" or "lookup" table. An example of one of those two would be a list of countries or states. This situation is what we call a bridge table, because you are bridging the two relationships and breaking a "many-to-many" relationship, which is rather impossible to visualize.

Sorry I can't help with your problem, but I felt that that was necessary information nonetheless, maybe to prevent some future confusion of some kind :)
0
 
LVL 3

Accepted Solution

by:
steeza earned 2000 total points
ID: 24312679
0
 

Author Closing Comment

by:Phreak3eb
ID: 31578263
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question