Every time I've introduced NH to a group they always go down the road of only including the "Id" value on child objects, and it always bites them. I highly recommend adding the complete bidirectional relationship; it exists logically and physically (foreign keys), so why try to hide that?
From: [email protected] [mailto:[email protected]] On Behalf Of Diego Mijelshon Sent: Thursday, April 15, 2010 1:14 PM To: [email protected] Subject: Re: [nhusers] Cascading Inserts without bidirectional relation Why do you need to avoid the bidirectional relationship in the first place? That's the standard way to represent this domain. Diego On Thu, Apr 15, 2010 at 15:27, Dinesh <dinesh.ms<http://dinesh.ms>@gmail.com<http://gmail.com>> wrote: I would like to Cascade Save operation from Parent to Child without using the bi-directional relation of having the parent represented as a property in the Child through Many-to-One relation. Using the class Order - Orderline example i have setup relation such that Order.LineItems is defined as a One-to-Many bag with inverse =true. <bag cascade="save-update" inverse="true" lazy="true" name="LineItems"> <key> <column name="OrderId" /> </key> <one-to-many class="OrderLine" /> </bag> However my OrderLine does not have a relation to Order, but just the OrderId property <property name="OrderId"/> Until now i was able to manage with the help of method in Order called AddLineItem which adds the OrderLine to LineItems collection and also set the OrderId on the OrderLine. But this approach does not work if the Order itself is new since OrderId is 0. public virtual void AddLineItem(OrderLine item) { item.OrderId = Id; LineItems.Add(item); } Is there any other approach to do cascade inserts without the bidirectional relation. I want to avoid having bidirectional so that the Order reference on the child is not used. Regards Dinesh -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]<mailto:[email protected]>. To unsubscribe from this group, send email to [email protected]<mailto:nhusers%[email protected]>. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
