hi,
ive been doing alot of reading on the parent child assocations and from everything i have read it doesnt seem possible to automatically create the assocation of the parent in the child record.
Unless I have the two lines in the code to associate the newInvoiceLineItemOne.invoice = newInvoice i cant get the id to insert to the invoice line item table.
Is this required?
Is there a cleaner way to do this?
here is an example of what I am trying to do
Code:
Invoice newInvoice = new Invoice();
InvoiceLineItem newInvoiceLineItemOne = new InvoiceLineItem();
newInvoiceLineItemOne.description = "description one";
InvoiceLineItem newInvoiceLineItemTwo = new InvoiceLineItem();
newInvoiceLineItemTwo.description = "description two";
newInvoice.invoiceLineItems.Add( newInvoiceLineItemOne );
newInvoice.invoiceLineItems.Add( newInvoiceLineItemTwo );
newInvoiceLineItemOne.invoice = newInvoice; //shouldnt be necessary??
newInvoiceLineItemTwo.invoice = newInvoice; //shouldnt be necessary??
Db.Save(newInvoice);
here are my mappings
Code:
<class name="SS.Invoice, SS" table="INVOICE" discriminator-value="?">
<id name="invoiceId" column="INVOICE_ID" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<bag name="invoiceLineItems" lazy="true" inverse="true" cascade="all">
<key column="INVOICE_ID" />
<one-to-many class="SS.InvoiceLineItem, SS" />
</bag>
</class>
<class name="SS.InvoiceLineItem, SS" table="INVOICE_LINE_ITEM" discriminator-value="?">
<id name="invoiceLineItemId" column="INVOICE_LINE_ITEM_ID" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<many-to-one name="invoice" column="INVOICE_ID" class="SS.Invoice, SS" cascade="none" />
<property name="description" column="DESCRIPTION" type="String" />
</class>
edit: for clarity
As always, thanks! for your feedback.
Sean