[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Map Reference Table with NHibernate

Posted on 2009-05-05
4
Medium Priority
?
1,066 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

656 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