Hi SriSamp,
I had the same "problem" a couple of days ago. Here is one of my test-mappings. It's not finetuned, but you can get a feeling how it should work. :)
Some other stuff is included in the mapping files. E. g. a parent-child mapping in table Hierarchy. Just take a look. :)
ExternalItem
Code:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.ExternalItem, ConsoleApplication1" table="ExternalItem">
<id name="Id" type="int" column="ID" access="field.pascalcase-m-underscore">
<generator class="identity"/>
</id>
<property name="Buid" column="BUID" type="String"/>
<property name="ImportFlag" column="ImportFlag" type="String"/>
<property name="Status" column="Status" type="String"/>
<bag name="RelExternalItemHierarchies" lazy="true" access="field.pascalcase-m-underscore">
<key column="ItemID" />
<one-to-many class="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1" />
</bag>
<bag name="RelExternalItemProperties" lazy="true" inverse="true" access="field.pascalcase-m-underscore">
<key column="ItemID" />
<one-to-many class="ConsoleApplication1.RelExternalItemProperty, ConsoleApplication1" />
</bag>
</class>
</hibernate-mapping>
Linktable RelExternalItemHierarchryCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1" table="RelExternalItemHierarchy">
<id name="Id" type="Decimal" column="ID" unsaved-value="0" access="field.pascalcase-m-underscore">
<generator class="native"/>
</id>
<many-to-one name="Item"
class="ConsoleApplication1.ExternalItem, ConsoleApplication1"
column="ItemID"
cascade="all"/>
<many-to-one name="Hierarchy"
class="ConsoleApplication1.Hierarchy, ConsoleApplication1"
column="HierarchyID"
cascade="all"/>
<property name="Buid" column="BUID" type="String"/>
<property name="Status" column="Status" type="String"/>
<property name="Modified" column="Modified" type="DateTime"/>
</class>
</hibernate-mapping>
HierarchyCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ConsoleApplication1.Hierarchy, ConsoleApplication1" table="Hierarchy">
<id name="Id" type="Decimal" column="ID" unsaved-value="0" access="field.pascalcase-m-underscore">
<generator class="native"/>
</id>
<many-to-one name="Parent" column="ParentID" class="ConsoleApplication1.Hierarchy, ConsoleApplication1"/>
<bag name="Hierarchies" lazy="true">
<key column="ParentID"/>
<one-to-many class="ConsoleApplication1.Hierarchy, ConsoleApplication1"/>
</bag>
<property name="Buid" column="BUID" type="String"/>
<property name="HierarchyName" column="HierarchyName" type="String"/>
<property name="Status" column="Status" type="String"/>
<property name="Modified" column="Modified" type="DateTime"/>
<bag name="RelExternalItemHierarchies" inverse="true" lazy="true">
<key column="HierarchyID"/>
<one-to-many class="ConsoleApplication1.RelExternalItemHierarchy, ConsoleApplication1"/>
</bag>
</class>
</hibernate-mapping>
Through the
lazy option I'm able to access the Hierarchy/ies of an ExternalItem by accessing the list of RelExternalItemHierarchy and through each RelExternalItemHierarchy object I have access to the corresponding Hierarchy object.
I hope you could follow this explanaition. ;) In Visual Studio you can follow the described "path" if you set a breakpoint. Now you're able to view the attributes of e. g. ExternalItem during runtime and of course you're able to follow the "lazy loading" path. :)
Greetings,
Chavez