Jide,
This implementation is different from the one in the other topic (it uses
inheritance and a discriminator) and that is why I decided to post it in a
separate question. This is one implementation suggested by a friend, and I
was not asking how to implement the concept, I was just asking why the
implementation was flawed. In anyway, I can link to it if necessary.



On Mon, Aug 16, 2010 at 10:00 PM, JideO <[email protected]> wrote:

> MSD,
>
> You decided to repost the solution I suggested to you on the earlier
> topic:
> http://groups.google.com/group/nhusers/browse_thread/thread/1d2319f44...
> as a different topic instead of continuing with the previous
> discussion. You will make it difficult other people including myself
> who were following the previous discussion to benefit from the
> contribution from the community on the topic.
>
>
> Apparently you have not properly implemented the mappings.
>
>
> Jide
>
>
>
>
> On Aug 16, 1:33 pm, Fabio Maulo <[email protected]> wrote:
> > various causes:
> > 1) your id (native) is unique in a class hierarchy (you have Employee#1
> and
> > Student#1)
> > 2) you are using the same column (EntityID) for both reference in a
> > table-per-class-hierarchy
> > 3) you are lucky; have a look to FKs created for EntityID column
> >
> > Solution:
> > use two different column-name for the relation
> >
> >
> >
> >
> >
> > On Mon, Aug 16, 2010 at 9:23 AM, MSD <[email protected]>
> wrote:
> > > 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]<nhusers%[email protected]>
> <nhusers%[email protected]<nhusers%[email protected]>
> ­>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
> >
> > --
> > Fabio Maulo- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
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