A simple question re开发者_StackOverflowgarding how NHibernate works:
I have a parent entity that has a collection of other child entities. Those child entities have a reference to the parent entity they belong to. Now I want to implement an Add method to the parent entity that would add a child to it. Should that Add method only add the child to its new parents collection, or should it also update the parent reference of the child or should it also remove the added entity from its previous parents collection? Do I have to do all these things in that method or will NHibernate do something for me?Thanks.
You should definitely make sure that the relationship is "valid" for all parties involved.
Make sure that the parent has the child in its children
collection, and the the child has the parent in its parent
reference, and that the child is removed from its old parent
(if it had one). The last step is the only one for which I'm not sure it's mandatory.
精彩评论