http://www.objectmentor.com/resources/articles/lsp.pdf

On Wed, Nov 24, 2010 at 7:19 AM, Pancake <[email protected]> wrote:

> I am having trouble with NHibernate's creation of proxy ("ghost")
> objects to support lazy loading of collections.
>
> I have an abstract base class ("Foo") which has several derived
> classes ("Bar", "Baz").  Another class maintains a collection of these
> objects - it is an IList<Foo>, and it is set to lazy load this
> collection.  The mapping for this looks like this:
>
>    <list name="FooList" lazy="true" cascade="all-delete-orphan"
> table="tblFoos">
>      <key column="ParentID" />
>      <index column="Position" />
>      <many-to-many column="FooID" class="Foo" />
>    </list>
>
> In my UI, I need to downcast the Foo objects to Bar or Baz objects in
> order to display them correctly. This is where the problem occurs.
> Sometimes the cast succeeds, and other times the cast fails because NH
> has created a proxy Foo object.
>
> I looked through the NH debug logs and found some clues.  What appears
> to be happening is that some of my objects are in the session cache
> fully-hydrated (as Bar or Baz objects), while others are Foo proxies.
> (The fully-hydrated objects are the result of prior operations in the
> session.)  When I iterate over my FooList, if the the object in the
> session cache happens to be a proxy, I get an exception when I
> downcast it.
>
> I guess what I'm looking for is a way to tell NH to ignore proxy Foo
> objects in the session cache if a subsequent access would otherwise
> return fully-hydrated Bar or Baz objects (if they weren't in the
> cache.)
>
> Any advice on how to handle this would be appreciated.
>
> Thanks,
> P
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>


-- 
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.

Reply via email to