In my domain I have a Company entity which has a many-to-many mapped
collection of SicCode object.
In C#:
public class Company {
public IList<SicCode> SicCodes { get; set; }
}
In hbm.xml:
<class
name="RRA.Beacon.Recruiter.Business.Entities.Company,RRA.Beacon.Recruiter.Business"
table="Company" lazy="false" optimistic-lock="version">
<idbag name="SicCodes" table="CompanySic" cascade="none"
lazy="true" batch-size="100">
<collection-id type="Int32" column="ID">
<generator class="native"/>
</collection-id>
<key column="CompanyID" />
<many-to-many
class="RRA.Beacon.Recruiter.Business.Entities.SicCode,
RRA.Beacon.Recruiter.Business" column="SicCodeID" lazy="false" />
</idbag>
</class>
Now I would like to be able to query this mapping using the SQL Exists
operator to find companies that are relevant to particular SicCode.
In SQL terms, I'd like to get to the following:
SELECT ...
FROM Company c
WHERE EXISTS (
SELECT 1
FROM CompanySic cs
INNER JOIN SicCode s ON cs.SicCodeID = s.ID
WHERE s.Code = '11050'
AND cs.CompanyID = c.ID )
Currently my querying is done through the Criteria API and / or
NHibernate Query Generator. Can anyone provide any advice here? I've
tried using SubQueries.Exists, but it doesn't seem to provide the
correlation back to the Company table (i.e. it leaves out the "AND
cs.CompanyID = c.ID").
TIA,
John
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---