c# - nhibernate returns an empty collection -
i have scenerio saving graph of objects , need retrieve later on in process. simple case of data manupulation really.
the problem after successful save of object , associated collection- indicated output insert statements- subsequent query same object returns empty collection associated collection. call flush() before that. strangely, closing , reopening application makes return populated collection.
i have mapping appointment class
<set name="workhours" inverse="true" cascade="all" lazy="true"> <key> <column name="person" /> </key> <one-to-many class="workhour" /> </set>
here's code data retrieval
method1() { dataaccessmanager.startoperation(); ienumerable<entity> q = getqueryprovider(); if (total > 0) { q = q.skip(startindex).take(total); } totalfound = q.count(); ilist<entity> list = q.tolist(); dataaccessmanager.endoperation(); return list; } protected override ienumerable<entity> getqueryprovider() { return dataaccessmanager.getqueryprovider<appointment>(); }
and saving
if (this.patient.appointments== null) this.patient.appointments= new iesi.collections.generic.hashedset<appointment>(); this.patient.appointments.add(this); if (this.doctor.appointments== null) this.doctor.appointments= new iesi.collections.generic.hashedset<appointment>(); this.doctor.appoint.add(this); entity ent = base.save(); return ent; //the base call: dataaccessmanager.startoperation(); try { entity t = dataaccessmanager.save<entity>(this); dataaccessmanager.endoperation(); return t; } catch (nhibernate.hibernateexception ex) { //handling } //the data access save method public t save<t>(t t) t : entity { try { currentsession.saveorupdate(t); return t; } ///exception handling , stuff }
i end session commit() , disconnect() .
never mind it, wasn't setting associations before saving.
Comments
Post a Comment