I have two associated business objects - A and B. the association is (A->B)many-to-one, with B.Id a foreign key in A (so A has A.B_id in the DB).
I m using lazy=true and solved most of my problems, however in A s ToString I want to print also A.B.Id, which I should have without further trips to the DB. but accessing A.B activates the proxy, and since this isn t in the context of an open session, throws an exception.
one easy but ugly solution would be to have A.B_id property. but that s part of the stuff we were trying to avoid in the first place. any "organic" way to do this? :) thanks!
UPDATE: just read about caching and Session.Get vs. Session.Load. before I only new that one throws an exception if the object doesn t exist (Session.Load), and the other returns a null object (Session.Get). after reading about caching here, it s clear that Session.Load returns a proxy to the object, and only lazily fetches it when a property other than the ID is accessed, which is very much like what I need from associations! for now I added the separate object ids (added B_Id to A so I can access it as A.B_Id instead of using A.B.Id)