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
-~----------~----~----~----~------~----~------~--~---