-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to query many to many relationship?
PostPosted: Tue Sep 06, 2011 4:22 am 
Newbie

Joined: Thu Aug 11, 2011 6:06 am
Posts: 3
I am very new to NHibernate, and I would like to start development using this great technology.
Below is my table relation ship:
Image

And the following are the xml schemas that I have created

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Airport, TelDir.Core" table="tblAirport" lazy="false">
    <id name="ID" column="AirportID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="AirportShortName" column="AirportShortName" />
    <property name="AirportFullName" column="AirportFullName" />

    <set name="Groups" cascade="none" table="tblAirportGroup" lazy="false" access="readonly">
      <key column="AirportId"/>
      <many-to-many class="TelDir.Core.Domain.Group, TelDir.Core" column="GroupId"/>
    </set>


  </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Group, TelDir.Core" table="tblGroup" lazy="false">
    <id name="ID" column="GroupID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="GroupName" column="GroupName" />   
 
    <bag name="Airports" cascade="none" table="tblAirportGroup" lazy="false" >
      <key column="GroupID"/>
      <many-to-many class="TelDir.Core.Domain.Airport, TelDir.Core" column="AirportId"/>
    </bag>
  </class>
</hibernate-mapping>




Does my mapping is correct? How can I do to retrieve list of Group(GroupName) that belong to a Airport?

I have tried using this syntax

Quote:
ISession session = NHibernateSessionManager.Instance.GetSession();
ISet<Group> rValue = session.CreateCriteria(typeof(Airport))
.CreateCriteria("Groups")
.Add(Expression.Eq("ID", ap.ID))
.List() as ISet<Group>;


but it give me no result.

Could you please guide me on that?

Best regards,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.