I have these domain models(simplified):

        public class Role : Entity
        {
                public Role() { }

                public virtual IList<Employee> Employees { get; protected set; }
        }

        public class Employee : User
        {
                public Employee() { Role = new Role(); }

                public virtual Role Role { get; protected set; }
        }

    public class User : Entity
    {
        public virtual UserType Type { get; set; }//UserType is an
emum. i.e. Employee = 1
    }

Here are the mappings. Employee is a discriminator.

        <class name="User" table="Users" abstract ="false">
                <id name="Id" type="Int32" column="Id">
                        <generator class="identity" />
                </id>
                <discriminator column="Type"/>
                <property name="Type"/>
                <subclass name="Employee" discriminator-value="1">
                        <many-to-one name="Role" column ="Id" class ="Role"/>
                </subclass>


        <class name="Role" table="Roles">
                <id name="Id" type="Int32" column="Id">
                        <generator class="identity" />
                </id>

                <bag name="Employees" cascade ="all-delete-orphan">
                        <key column="Id"  />
                        <one-to-many class="Employee" />
                </bag>
        </class>

When I called IRepository.SaveOrUpdate(employee), I kept getting an
error. The generated sql query was trying to update the primary key of
the User table. That's why it failed. The problem was solved when I
removed the column and class attributes of the many-to-one element:

<many-to-one name="Role" />

Does the column or the class attribute do anything special to table
per hierarchy mapping? Is that an expected behavior?

Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to