I'm not sure how a custom collection type would help (doesn't NHibernate still require that it be implemented as an interface?), but, there's been a design change and I've run into a totally different problem.
So first, I'd like to ask if anyone out there has implemented their own lazy loading solutions using NHibernate where sessions are always closed after each operation? If not, is this kind of design, where an ISession is opened for each CRUD operation and closed afterwards, a bad design? I don't want to couple the application to NHibernate (we are actually testing it and ultimately we may go with a different solution), so I can't have session-management issues move outside the repositories assembly where NHibernate is used. If it is not definitively bad, or even if it is just reasonable, then I'd really like to know how others are implementing custom lazy- loading when the parent objects are detached. My hoped-for solution was to use a wrapper like the Lazy<T> class suggested by Jeremie here: http://thinkbeforecoding.com/post/2009/02/07/Lazy-load-and-persistence-ignorance. However, this has turned out not to work because: - Database contains 2 tables, call them Parents and Children, where the Children table contains a ParentId column (1:* mapping Parent:Children) - Object model contains 2 classes, call them Parent and Child, where Parent contains a collection of Child entities, which know nothing about the parent. - There is no method I can use that would load the Children for a given parent, because I always end up with recursive calls (to load a parent's children, 1. Load the parent, 2. Get its children, which 3. Load the parent again, etc.). On Aug 12, 6:13 am, Fabio Maulo <[email protected]> wrote: > Custom collection type. > > 2009/8/11 joniba <[email protected]> > > > > > > > Hi all, > > > I have a parent entity that contains a collection of child entities. I > > have a custom lazy-loading implementation, because we work detached (a > > session is created for every operation). This lazy-loading > > implementation doesn't support loading collections as interfaces (due > > to some weird c# language limitation). So I'd like to know if there's > > any way to tell NHibernate NOT to load a collection? Because defining > > lazy=true for this collection still throws an error because it's still > > trying to cast an empty collection to a non-interface type. > > > I still want this collection to be mapped, for inserts updates and > > deletes. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
