I am designing an OO object model with a plan to use NHibernate as the data access layer.
I'd like to know the best OO design when dealing with two entities that have a many to many relationship with each other (especially for easy integration with NHibernate).
The objects: User - a single User can be related to multiple Subjects Subject - a single Subject can be related to multiple Users
In SQL, this relationship is straight forward using a many to many table;
tblUser
userID
tblSubject
subjectID
tblUserSubject
userSubjectID
userID
subjectID
So, how should the pure objects be created? Should each object contain a collection of the other? Example:
class User
{
public int userID {get; set;}
public List<Subject> subjects {get; set;}
}
class Subject
{
public int subjectID {get; set;}
public List<User> users {get; set;}
}
Is there a better way to model this so that NHibernate can easily persist the relationships?