I am very new to NHibernate, and I would like to start development using this great technology.
Below is my table relation ship:
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,