Roger... Perhaps we should implements a custom ParentChildSet and ParentChildBag somewhere ? What do you think ?
On Thu, Jun 3, 2010 at 8:34 AM, Roger Kratz <[email protected]>wrote: > Don't expose the mutable collection. Instead have something like... > > department.AddUnit(new Unit()); > department.RemoveUnit(someUnit); > > ...and handle the birefs inside these methods. > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On Behalf > Of Skiv > Sent: den 3 juni 2010 10:17 > To: nhusers > Subject: [nhusers] Beginners question: How to add or delete related entity > > For example, I have entity with one to many relation: Department has > many Units: > > class Department > { > public decimal Id{get;set;} > public IList<Unit> Units{get;set;} > } > > class Unit > { > public decimal Id{get;set;} > public Department {get;set;}//Parent > } > > If I want add new Unit: > Unit newUnit =new Unit{Department=someDepartment}; > session.Save(newUnit); > > So, if I already have parent Department, it's Units collection isn't > updated automatically, I must add it manually: > someDepartment.Units.Add(newUnit); > > Same is with entity deletion: > Unit deletedUnit = someDepartment.Units[0]; > session.Delete(deletedUnit); > deletedUnit.Department.Units.Delete(deletedUnit); > > Is this ok? Maybe there is more convenient way to do this? > > -- > 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]<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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- 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.
