Hi,
i would like to know if nhibernate is able to save objects in an aggregated way:
I have and Order which has a list of OrderLine.
What i would like to do is:
Order order = new Order(..);
order.OrderLine.Add(new OrderLine(..));
NHibernate.Save(order);
So this should save the order and the orderline in the list.
The problem i have is that NHibernate doesn't set the "IdOrder" property of the OrderLine (FK) to the new ID of Order (PK).
Is it possible to do this ?
Thanks :)
Mapping code:
Quote:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Project.MyProject.Core.Domain.Order, Project.MyProject.Core" table="Orders" lazy ="false">
<id name="ID" column="ID">
<..../>
</id>
<version name="Version" unsaved-value="negative"/>
<property name="Description" column="Description" type="String" length="255" not-null="true"/>
<property name="OrderDate" column="OrderDate" type="DateTime" not-null="true"/>
<property name="idCustomer" access="field" column="IdCustomer" type="Guid" not-null="true"/>
<many-to-one name="customer" access="field" column="IdCustomer" class="Project.MyProject.Core.Domain.Customer, Project.MyProject.Core" update="false" insert="false" not-null="true" />
<bag name="orderLines" access="field" generic="true" cascade="all" table="OrderLine" lazy="false" inverse="false">
<key column="idOrder" />
<one-to-many
class="Project.MyProject.Core.Domain.OrderLine, Project.MyProject.Core" />
</bag>
</class>
</hibernate-mapping>