Hi all,
I have just started using nHibernate and would appreciate any help with a solution for following mapping scenario.
Domain Objects
The domain objects are Employee and Access Cards. An Employee can have multiple types of Abstract Access cards such as Permanent Card, Temporary Card, Special Previlege Card.
A permanent card is always linked to an Employee.
A temporary card is only issued when an employee loses or forgets his card and is activated for a pre-set number of days. Temporary Cards are re-used. A temporary card may or may not be linked to an employee at any given time.
A Special Previlege Card is given to external consultants and is not linked to an Employee.
PermanentCard, TemporaryCard and SpecialPrevCard are all derived from AbstractAccessCard.
Employee has a IDictionary of AbstractAccessCards and in turn AbstractAccessCard refers to an Empoyee Object.
Database Tables
The database tables are Employees, EmpAccessCards and AccessCards. EmpAccessCards table is used for breaking the many-to-many relationship (for rotation of Temporary Cards). For Permanent cards there is only one instance per card in EmpAccessCards. For Special Previlege cards there is no entry in EmpAccessCards as they don't belong to any employee.
Although in the domain objects the relationship between Employee and Access Cards is one-to-many in database implementation it's many-to-many as Temporary cards can be rotated between employees. But at any one time only one instance of temporary card is actively linked to a employee based on date field in EmpAccessCards table.
My Question
Now in my mapping files I can't use many-to-many relationship as the domain objects see this only as a one-to-many or many-to-one relationship whilst the database implementation is a many-to-many?
Also is there a way to map a class to multiple tables instead of only one table and use where clause?
If the issue is unclear pls let me know and I will attach a domain model and ER Diagram.
Regards,
Kal
|