Hey _carl_,
If you want to model it with two tables, it'll look something like this
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<!-- MULTI TABLE IMPLEMENTATION -->
<class name="Test.Node, Test" table="Nodes">
<id name="NodeId" type="System.Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" not-null="true"></property>
<bag name="Children" table="Connections" lazy="true" inverse="true" cascade="save-update">
<key column="NodeIdParent"></key>
<one-to-many class="Test.Node, Test" ></one-to-many>
</bag>
</class>
</hibernate-mapping>
You could also do it with just a single table and do it like this...
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<!-- SINGLE TABLE IMPLEMENTATION -->
<class name="Test.Node, Test" table="Nodes">
<id name="NodeId" type="System.Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" not-null="true"></property>
<many-to-one name="Parent" column="NodeIdParent" not-null="false" cascade="save-update"></many-to-one>
<bag name="Children" lazy="true" inverse="true" cascade="save-update">
<key column="NodeIdParent"></key>
<one-to-many class="Test.Node, Test" ></one-to-many>
</bag>
</class>
</hibernate-mapping>
DISCLAIMER: This isn't mapping isn't tested...so there may be some bugs.
-Ben
_carl_ wrote:
Hi,
I'm a beginner of NHibernate and need some help.
I have these database tables:
Nodes
---------
id:int
name:string
Connections
------------
scorecardId:int
nodeId:int
How would the xml look like if I want the class to look like this:
Node
-----------
ScorecardId:int
Children:IList
Name:string
Any help is appreciated!
/Carl