I have a many-to-many relationship between a Site (workplace) and an 
Individual with an intersection table SiteIndividual. The SiteIndividual 
table contains a flag,  IndividualWorkingSiteInd , that when true indicates 
the individuals primary workplace.

 

public class Site

{

    public virtual long SiteId { get; set; }

    public virtual string SiteName { get; set; }

    public virtual ICollection<SiteIndividual> SiteIndividuals { get; set; }

}

 

public class Individual

{

public virtual long IndividualId { get; set; }

public virtual string Name { get; set; }

public virtual ICollection<SiteIndividual> SiteIndividuals { get; set; }

}

 

public class SiteIndividual

{

  public virtual Site Site { get; set; }

  public virtual Individual Individual { get; set;}

  public virtual bool IndividualWorkingSiteInd { get; set; }

}

 

<class name="SiteIndividual" table="SITE_INDIVIDUAL" lazy="true" >

    <composite-id>

        <key-many-to-one name="Site" column="SITE_ID" lazy="proxy" 
class="Model.Site, Model"/>

        <key-many-to-one name="Individual" column="INDIVIDUAL_ID" 
lazy="proxy" 

            class="Model.Individual, Model" />

    </composite-id>

    <property name="IndividualWorkingSiteInd" type="YesNo">

        <column name="INDIVIDUAL_WORK_SITE_IND" />

    </property>

</class>

 

Is there any way to load the Individuals primary site into a property, say 
PrimarySite of type Site, on the Individual entity or do I have to run 
multiple queries, one to load an Individual with all and then one to 
retrieve the Individuals primary work site?

 

public class Individual

{

    ....

    public virtual Site PrimarySite { get; set; }
} 
 
I cannot change the database but is there a better way to implement my 
classes or my mapping files?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/QqJMW9m2ya8J.
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