For sure.... lazy-fields is only a mere hope in .NET with no IL rewriter
(ej. PostSharp).
In NH it is implemented using DynamicProxy so it is not a truly
field-interceptor but just a methods-interceptor (a property has 2 methods).
In some circumstances the usage of lazy-properties may generate a proxy of
a proxy of an instance; it should work in the mayor part of cases...
If you have a failing test perhaps somebody may look at it to let you know
if it represent a not supported scenario, a bug in your code or a bug in NH.

On Thu, Feb 9, 2012 at 3:57 AM, pvginkel <[email protected]> wrote:

> I don't have a reference to the session on my entity. Internally, it
> redirects back to a static utility method that eventually gets a
> session using the conversation model as described on
> http://fabiomaulo.blogspot.com/2009/01/using-conversation-per-business.html
> .
> The problem here is that I pass the wrong entity to that static
> method.
>
> The reason I am posting this on nhdevs is that I believe this may not
> be ideally implemented. I can think of a number of use cases that
> break through this implementation. For example, if you have business
> logic on your entities (DDD) and you use the this pointer of the
> entity to perform further actions, you are always passing the wrong
> entity because the interceptor redirects everything to the
> TargetInstance. NHibernate really doesn't know of the TargetInstance
> and only just knows of the info.Target. This to me looks like a
> deficiency in the implementation of lazy fields.
>
> If I am overlooking something and you don't agree that this is an
> issue with the implementation, I'd be happy to look for help in other
> places.
>
> On Feb 8, 4:10 pm, Diego Mijelshon <[email protected]> wrote:
> > Well, not having a session reference in your entities would be a good
> start.
> > If you like that kind of pattern, I recommend you use Castle ActiveRecord
> > instead of implementing it yourself.
> >
> > On a different note, this list is only for development OF NHibernate. Try
> > nhusers (or StackOverflow) for usage questions.
> >
> >     Diego
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Feb 8, 2012 at 06:09, pvginkel <[email protected]> wrote:
> > > I have a virtual method on my Entity base class which calls
> > > session.SaveOrUpdate. When the entity has lazy fields, the
> > > DefaultDynamicLazyFieldInterceptor calls the virtual method with the
> > > TargetInstance and not the info.Target. This means that SaveOrUpdate
> > > fails with a NonUniqueObjectException because I'm not passing the
> > > proxy to SaveOrUpdate.
> >
> > > Is this behavior correct? If so, is there a way around this?
>



-- 
Fabio Maulo

Reply via email to