.net - NHibernate + JSON/Ajax Parent/Child Relationships? Why this isn't working? -
i have typical parent/child relationship. writing news in .net
, adding children works fine, nhibernate
plays nice , adds correct relationships.
however, when passing json object
client method serializes json .net representation, nhibernate seems confused. comes correct query add parent (and assigns new guid id), however, doesn't associate parent id children objects in `sql tries execute. came quick , dirty hack, list below - wondering, there i'm missing here?
ilist<backerentry> backerstemp = new list<backerentry>(); foreach (backerentry backerentry in jsonbackerentity.backerentries) { backerstemp.add(backerentry); } jsonbackerentity.backerentries.clear(); foreach (backerentry backerentry in backerstemp) { jsonbackerentity.addchild(backerentry); }
doing way way can seem nhibernate see these children belong parent. inside addchild method looks this:
public virtual void addchild(backerentry backerentry) { if (backerentry.backer != null) { backerentry.backer.backerentries.remove(backerentry); } backerentry.backer = this; this.backerentries.add(backerentry); }
edit: think may have realized why - because not sending parent property of child in json. i'm not sure if that'd possible, due circular nature of two. child has parent (who in json has child original child has parent, etc)... ideas?
before saveorupdate hibernate must ensure objects childs has same memory object parent. review mappings , think every row on database 1 , 1 memory object, make sure true you, , reset parentobjects fit this.
also, try merge method more flexible.
Comments
Post a Comment