orm - nHibernate Save One-To-Many -
i have parent class contains list of children. have parent , child mapped bidirectional has-many , inverse on parent cascade.all turned on. if modify object in child list, no property on parent, nhibernate not save child. if modify property on parent saves fine. design or there special property need set?
this might have way adding children collection. in bidirectional, have manage both sides of relationship in code. consider example fluent nhibernate getting started guide. check store entity.
a store has many employees. staff property of store collection of employees. relationship setup bidirectional.
store has following method
public virtual void addemployee(employee employee) { employee.store = this; staff.add(employee); }
as can see, childs parent property needs set parent object. if not done, nhibernate not able understand parent of child , cannot automatically save child if child modified , saveorupdate(parent) called.
you need both.
Comments
Post a Comment