I have the following:

   - Employee table maps to Employee class
   - Manager table maps to Manager class
   - AwardedPersons table which contains column 'PersonId', which is a 
   foreign key to employee in either Employee or Manager table


Both Employee & Manager are derived from a 'Person' class.

When an employee receives an award, I want an entry to be made in the 
AwardedPersons table. However, when an employee becomes a manager, the 
record is deleted from 'Employee' and moved to 'Manager', but the record id 
is reused as an id in the new table.

Currently I have:

public class AwardedPerson
{
 public IEmployee Employee {get;set;}
 public IManager Manager {get;set;}
}

public AwardedPersonsMap()
        {
            this.Id(
                p => p.Id,
                map =>
                {
                    map.Column("Id");
                    map.Generator(Generators.Native);
                });

            this.Table("AwardedPersons ");
            this.Lazy(false);
            this.Property(p => p.Date);

            this.ManyToOne(
                p => p.Employee,
                map =>
                {
                    map.Column("EmployeeId");
                    map.Class(typeof(Employee));
                    map.Cascade(Cascade.None);
                });

            this.ManyToOne(
                p => p.Manager,
                map =>
                {
                    map.Column("ManagerId");
                    map.Class(typeof(Manager));
                    map.Cascade(Cascade.None);
                });
        }

The above works, but I would prefer:

public class AwardedPerson
{
 public IPerson Person {get;set;}
}

public AwardedPersonsMap()
        {
            this.Id(
                p => p.Id,
                map =>
                {
                    map.Column("Id");
                    map.Generator(Generators.Native);
                });

            this.Table("AwardedPersons ");
            this.Lazy(false);
            this.Property(p => p.Date);

            this.ManyToOne(
                p => p.Person,
                map =>
                {
                    map.Column("PersonId");
                    map.Class(typeof(Person));
                    map.Cascade(Cascade.None);
                });      
        }

However, this doesn't work as NHibernate wants a PersonMap, but I don't 
know how to impement that as there is no Person table?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to