I have a Node and NodeType class, simple foriegn key from NodeType to Node. In C# I want to create a node, create a nodetype, set the node's NodeType property to my newly created nodetype, and save the node. I was hoping the when I save the node, NHibernate would know about the foriegn key, and insert the nodetype into the nodetype table before it inserts the node into the node table. This is not the case. I keep getting a foreign key exception. Is what I am trying to do possible? thanks
Node node = new Node();
NodeType nodeType = new NodeType();
nodeType.ID = 0;
node.NodeType = nodeType;
session.Save(node);
<class name="NodeType" table="NodeType">
<id name="ID">
<column name="ID" sql-type="Int32" not-null="true"/>
<generator class="assigned" />
</id>
<set name="Nodes" cascade="all" lazy="false">
<key column="NodeTypeID" />
<one-to-many class="Node" />
</set>
</class>
<class name="Node" table="Node">
<id name="ID">
<column name="ID" sql-type="char(32)" not-null="true"/>
<generator class="identity" />
</id>
<many-to-one name="NodeType"
class="NodeType"
column="NodeTypeID"
cascade="all"/>
</class>
|