When doing something like this:
Code:
(pseudo code obviously)
//customer is a customer loaded by NH from db with a list of associated orders
IList orders = customer.Orders
while (orders.hasnext)
{
Order currentOrder = (Order)orders.Next();
if(someClause)
{
//add new order
Order newOrder = new Order();
//I know this is wierd, but assume for a moment
//that in my real code, I only have access to a single order,
//and therefor have to navigate to its parent, in order to get a handle
//to the full list of orders.
currentOrder.Customer.Orders.Add(newOrder);
}
}
I get the error
not-null property references a null or transient value.
My mapping file for customer is:
Code:
<id name="Id" column="Id" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<bag name="Orders" table="Ordres" access="nosetter.camelcase" cascade="all" inverse="true" lazy="true" >
<key column="customerId"/>
<one-to-many class="foo.Order,foo"/>
</bag>
and in Orders I have:
Code:
<id name="Id" column="Id" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property column="Name" type="String" name="Name" not-null="true" length="32" />
<many-to-one name="Customer" column="CustomerId" class="foo.Customer,foo" not-null="true"/>
Does anyone know what I am doing wrong. I have read some posts which seem to point in the direction of the unsaved-value, but as I understand it it seems as if I were doing things correctly... Not sure what I am doing wrong.