Your example is correct. In my case (taking reference of your example only), entityA exists in database but entityB does not. so accessing entityA.ReferenceToEntityB returns proxy of entityB. When I try to access any property of this entityB then I get exception. Now what I can do is, I put a logic inside 'getter' of entityA.ReferenceToEntityB so it checks if that entityB exists in db (by accessing a property itself inside getter) and if NO then it returns NULL. I will have to put this logic in each getter.
On Apr 16, 11:41 am, Oskar Berggren <[email protected]> wrote: > Den 16 april 2012 08:32 skrev Raj <[email protected]>: > > > Currently I am using not-found="ignore" but I want to get away from > > it. Cleaning database is not an option for me. > > One way I found is to put necessary logic inside 'getter' of that > > entity i.e. if exception comes then return NULL... but that's does not > > seem to be a good way of doing it so looking for a better approach. > > If exception comes from what? > > To me it sound like you are trying to do: > > var entityA = session.Get(5); > var entityB = entityA.ReferenceToEntityB > > When the entityA instance is created, the entityB proxy will also be > created. The reference from entityA to that proxy cannot later > automatically be replaced by null just by accessing it. Perhaps > something more would be theoretically possible if entityA is also a > proxy. Or did you have some other pattern in mind? > > I think you will have to explore the NH code. > > /Oskar -- 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.
