Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate doesn't save object's collection of items
    primarykey
    data
    text
    <p>I've got an Order class that contains OrderItems. When I save the Order class, the database is populated with the Order information, but none of the child OrderItems are saved to their respective tables. Here's what the Order mapping looks like:</p> <pre><code>&lt;class name="Order" table="Orders"&gt; &lt;id name="OrderID" column="OrderID" type="Int64" unsaved-value="0"&gt; &lt;generator class="identity"/&gt; &lt;/id&gt; &lt;list name="OrderItems" table="OrderItems" inverse="true" &gt; &lt;key column="OrderID"/&gt; &lt;index column="OrderItemID" /&gt; &lt;one-to-many class="OrderItem" /&gt; &lt;/list&gt; </code></pre> <p></p> <p>Here's what the OrderItem mapping looks like:</p> <pre><code>&lt;class name="OrderItem" table="OrderItems"&gt; &lt;id name="OrderItemID" column="OrderItemID" type="Int64" unsaved-value="0"&gt; &lt;generator class="identity"/&gt; &lt;/id&gt; &lt;property name="OrderID" /&gt; &lt;many-to-one name="Order" class="Order" column="OrderID" not-null="true" /&gt; &lt;/class&gt; </code></pre> <p>Here's what the code to save the Order looks like:</p> <pre><code>if (o.CreatedBy == null || o.CreatedBy == string.Empty) { o.CreatedBy = userID.ToString(); foreach (OrderItem oi in obj.OrderItems) { oi.CreatedBy = userID.ToString(); oi.ModifiedBy = userID.ToString(); oi.ModifiedOn = DateTime.Now; } } o.ModifiedBy = userID.ToString(); o.ModifiedOn = DateTime.Now; ISession session = NHibernateHelper.GetCurrentSession(); ITransaction tx = session.BeginTransaction(); session.Save(o); tx.Commit(); NHibernateHelper.CloseSession(); </code></pre> <p>Any idea why the child OrderItems aren't being saved?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload