I have this domain model:
public class Role : Entity
{
public Role() { }
public virtual string Name {get; set;}
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 User() {}
public virtual UserType Type { get; set; }
}
And this mapping (simplified). 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>
<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>
I kept getting an error when trying to run an update query. When I
looked into the generated sql query, it was trying to update the User
Id, which is an identity key. This should not happen. But the problem
was fixed after I changed the many-to-one element by taking out the
column and class attributes:
<many-to-one name="Role"/>
Does the column attribute do anything special to table per class
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
-~----------~----~----~----~------~----~------~--~---