The solution to this has been in the public domain for awhile. Here is
some code from the open source Sharp Architecture project to
"unproxify" as needed:

        public override bool Equals(object obj) {
            var compareTo = obj as BaseObject;

            if (ReferenceEquals(this, compareTo))
                return true;

            return compareTo != null &&
GetType().Equals(compareTo.GetTypeUnproxied()) &&
                HasSameObjectSignatureAs(compareTo);
        }

        /// <summary>
        /// This allows the typing check that is rightly part of
equality to succeed even when one type is a lazily loaded proxy.
        /// </summary>
        /// <permission cref="http://groups.google.com/group/sharp-
architecture/browse_thread/thread/ddd05f9baede023a"/>
        protected virtual Type GetTypeUnproxied() { return
GetType(); }

Cookbook is a (very) worthwhile purchase for a similar solution as
well as many other insights, but this should help you out in the mean
time.

~ Berryl

On Feb 2, 9:31 am, Fabio Maulo <[email protected]> wrote:
> NHibernate3.0 Cookbook page 24-27
>
> On Wed, Feb 2, 2011 at 1:16 PM, Giulio Petrucci
> <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
> > Hello everybody,
>
> > here is my class hierarchy:
>
> > class A { ...}
> > class X : A { }
> > class Y : A { }
>
> > class Foo
> > {
> >   Int32 Id { get; }
> >   A MyAProperty { get; }
> > }
>
> > when I try to do the following:
>
> > ISession session = ...;
> > var foo = sessio.Get<Foo>(23);
> > if (foo.MyAProperty is A)
> >   ...
>
> > the IF condition evaluate always to 'false' as the property value's
> > type is a proxy for 'A'.
> > Could you suggest me any workaround? The first thing that came to my mind
> > is:
>
> > if (foo.MyAProperty as A != null)
> >   ...
>
> > Any suggestion?
>
> > Grazie,
> > Giulio
>
> > --
>
> > --
> > 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