I have the following classes:
public enum ContactValueType : short {...}
public abstract class ContactDetail
{
public int ID { get; protected set; }
public virtual ContactValueType ValueType { get; protected set; }
public virtual string Value { get; protected set; }
public ContactDetail(){}
public ContactDetail(ContactValueType valueType, string value)
{
this.ValueType = valueType;
this.Value = value;
}
}
public class StudentContactDetail : ContactDetail
{
public virtual Student Student { get; set; }
public StudentContactDetail(){}
public StudentContactDetail(Student student, ContactValueType
valueType, string value) : base(valueType, value)
{
this.Student = student;
}
}
public class EmployeeContactDetail : ContactDetail
{
public virtual Employee Employee { get; set; }
public EmployeeContactDetail(){}
public EmployeeContactDetail(Employee employee, ContactValueType
valueType, string value) : base(valueType, value)
{
this.Employee = employee;
}
}
public class Employee
{
public int ID { get; protected set; }
public virtual string Name { get; set; }
public virtual
Iesi.Collections.Generic.ISet<EmployeeContactDetail> ContactDetails
{ get; protected set; }
protected Employee()
{
ContactDetails = new
Iesi.Collections.Generic.HashedSet<EmployeeContactDetail>();
}
public Employee(string name) : this()
{
this.Name = name;
}
}
public class Student
{
public int ID { get; protected set; }
public virtual string Name { get; set; }
public virtual Iesi.Collections.Generic.ISet<StudentContactDetail>
ContactDetails { get; protected set; }
protected Student()
{
ContactDetails = new
Iesi.Collections.Generic.HashedSet<StudentContactDetail>();
}
public Student(string name): this()
{
this.Name = name;
}
}
their tables:
ContactDetail
ID int
EntityType char(1)
EntityID int
ValueType smallint
Value nvarchar(50)
Employee
ID int
Name nvarchar
Student
ID int
Name nvarchar
and their mappings:
<class name="ContactDetail" table="ContactDetail" lazy="false">
<id name="ID" column="ID">
<generator class="native"/>
</id>
<discriminator column="EntityType" type="String" />
<property name="ValueType" column="ValueType"/>
<property name="Value" column="Value"/>
<subclass name="StudentContactDetail" discriminator-value="S">
<many-to-one name="Student">
<column name="EntityID" />
</many-to-one>
</subclass>
<subclass name="EmployeeContactDetail" discriminator-value="E">
<many-to-one name="Employee">
<column name="EntityID" />
</many-to-one>
</subclass>
</class>
<class name="Student" table="Student" lazy="false">
<id name="ID">
<generator class="native"/>
</id>
<property name="Name">
<column name="Name" length="50" not-null="true" />
</property>
<set name="ContactDetails" fetch="select" lazy="false"
cascade="all">
<key column="EntityID" />
<one-to-many class="StudentContactDetail" />
</set>
</class>
<class name="Employee" table="Employee" lazy="false">
<id name="ID">
<generator class="native"/>
</id>
<property name="Name">
<column name="Name" length="50" not-null="true" />
</property>
<set name="ContactDetails" fetch="select" lazy="false"
cascade="all">
<key column="EntityID" />
<one-to-many class="EmployeeContactDetail" />
</set>
</class>
When persisting Student and Employee instances all is fine, but when
loading them, their ContactDetails collection is populated by ALL
ContactDetails, that is disregarding the discriminator in the select
statement.
Why is that and what can I do aside from this:
<set name="ContactDetails" fetch="select" lazy="false" cascade="all"
where="EntityType='E'">
(adding the where attribute).
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.