c# - NHibernate lazy collection wasn't loaded -


i have couple of classes whrapped via nhibernate , underlying db. fir exmaple, call classes following way:

class parent {   public virtual int id {get;set;}   public virtual string name {get;set;}   public virtual ilist<child> children {get;set;} }  class child {   public virtual int id {get;set;}   public virtual string name {get;set;}   public virtual ilist<child> children {get;set;} } 

of course have mappign , working fine in asp.net application. want intoduce unit test , faced strange error: in test setup method test data created (i.e. parent) , id stored in test class. in test method asking repo entity id , returns nnibernate proxy object (if remember right called bag). when trying access colelction of children have got , exception nhibernate.lazyinitializationexception : initializing failed lazily initialize collection of role

i read similr questions here of them recomment "just not close session". cannot it. there way retrieve collection on test data creation have access in future?

if insist on using test pattern, options re-attach object created in setup session in test method.

i'd suggest using session.lock(object, lockmode.none) see question , answer more details: attaching disconnected object nhibernate session; best practice?


Comments

Popular posts from this blog

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -