Sorry, a typo, I meant invers = false 2. With inverse=false, the many end (Children in this case) has no obligation to set the parent to which it belongs..
> You mean, that Child.Parent being null would be ok, i.e. a Child with > no parent? Well, I've read that in this case, NHibernate insert the children with parent_id = null and then execute another query to update the parent_id with the correct one. Am I right? ----- Original Message ----- From: "Oskar Berggren" <[email protected]> To: <[email protected]> Sent: Friday, August 21, 2009 11:02 AM Subject: [nhusers] Re: Inverse=True (again) 2009/8/21 Cesar Sanz <[email protected]>: > 2. With inverse=true, the many end (Children in this case) has no > obligation > to set the parent to which it belongs.. You mean, that Child.Parent being null would be ok, i.e. a Child with no parent? Well, NHibernate can handle it, it's up to you if you want to allow that in you domain model. Not sure if I understood you correctly. > > BTW, having a biderectional relationship, I saw somebody writing this > code, > which I think is cool. > > public class Parent > { > ... > private IList<Child> _children; > public IList<Child> Children {get {return _children; }; } // NOTE ONLY > "GET" IN THIS PROPERTY, NO SETTER > > public void AddChild(Child child) > { > child.Parent = this; > _children.Add(child); > } > } I tend to use similar code lately, but often I also make the get method return a read only copy of the collection, since I want to prevent other code doing parent.Children.Add(). Not completely sure yet of how bad or how good this is. At least I should probably return a read-only wrapper (instead of copy) for performance reasons. Another idea is to create you own derived collection and override Add() to do what AddChild() does above, but I'm not sure how that would work with proxies created by NHibernate. /Oskar --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
