@Diego: awesome, thank you for that.

@Fabio, agreed and thanks for that too. I put the link in the comments
for Diego's As<T> method along with the link to Diego's appropriately
titled "hacking lazy loaded inheritance"

~ Berryl

On Dec 19, 6:03 pm, Diego Mijelshon <[email protected]> wrote:
> Checkhttp://sessionfactory.blogspot.com/2010/08/hacking-lazy-loaded-inheri...
>
>     Diego
>
>
>
>
>
>
>
> On Sat, Dec 18, 2010 at 04:00, Berryl Hesh <[email protected]> wrote:
> > I suppose the mapping is not the issue here; since if I set lazy="no-
> > proxy" then the typing is as expected.
>
> > But is that my only choice here?
>
> > I thought that either accessing a property of the proxied object or
> > using NHibernateUtil.Initialize(object) would also get the correct
> > type.
>
> > ~ Berryl
>
> > On Dec 17, 4:19 pm, Berryl Hesh <[email protected]> wrote:
> > > I have an extension query that relies on an object knowing what
> > > subclass it is. It is a collection of proxies initially, and I can get
> > > at the base type of them but not the subclass. I'm not sure if I have
> > > a mapping problem or a proxy problem.
>
> > > The mappings and a test that exposes the problem are below.  How can I
> > > get the subclass info from the CastleProxy?
>
> > > Cheers,
> > > Berryl
>
> > > Mappings
> > > ============
> > > Allocation has an ActivitySubject
> > > ============
> > > <hibernate-...>
>
> > >   <class name="..."       table="Allocations"  >
>
> > >     <id name="Id" unsaved-value="0">
> > >       <column name="AllocationId" />
> > >       <generator class="hilo" />
> > >     </id>
>
> > >     <many-to-one class="ActivitySubject"
> > >                  foreign-key="ActivityBase_FK" name="ActivitySubject">
> > >       <column name="ActivitySubjectId" unique-key="DomainSignature" />
> > >     </many-to-one>
>
> > >     ....
>
> > >   </class>
>
> > > </hibernate-mapping>
>
> > > ================
> > > ActivitySubject is a base class
> > > ================
>
> > > <hibernate-mapping ...  >
>
> > >   <class name="ActivitySubject" table="ActivitySubjects" discriminator-
> > > value="BASE_CLASS">
>
> > >     <id name="Id" unsaved-value="0">
> > >       <column name="ActivitySubjectId" />
> > >       <generator class="hilo" />
> > >     </id>
>
> > >     <discriminator column="ActivitySubjectType" type="System.String" /
>
> > >     <property name="Description" length="75" not-null="true" />
> > >     <property name="BusinessId" length="25" not-null="true" />
>
> > >     <subclass name="Account" discriminator-value="ACCOUNT">
>
> > >       ....
>
> > >     </subclass>
>
> > >     <subclass name="Project" discriminator-value="PROJECT">
>
> > >       ...
>
> > >     </subclass>
>
> > >   </class>
>
> > > </hibernate-mapping>
>
> > > ==================
> > > example of problem
> > > ==================
>
> > >         [Test]
> > >         public void
> > > Allocation_ActivitySubject_SubclassTypeCanBeKnown()
> > >         {
> > >             _session.Clear();
>
> > >             Allocation found;
> > >             using (var tx = _session.BeginTransaction())
> > >             {
> > >                 found =
> > > _session.Get<Allocation>(_someTransientAllocation.Id);
> > >                 Assert.That(found.ActivitySubject,
> > > Is.EqualTo(_someTransientAllocation.ActivitySubject));
> > >                 Assert.That(found.ResourceSubject,
> > > Is.EqualTo(_someTransientAllocation.ResourceSubject));
> > >                 Assert.That(found.TimeRange,
> > > Is.EqualTo(_someTransientAllocation.TimeRange));
>
> > >                 NHibernateUtil.Initialize(found.ActivitySubject);
>
> > >                 // ok
> > >                 Assert.That(found.ActivitySubject,
> > > Is.InstanceOf<ActivitySubject>());
>
> > >                 // *** not ok
> > >                 Assert.That(found.ActivitySubject,
> > > Is.InstanceOf<Project>());
>
> > >                 tx.Commit();
> > >             }
> > >         }
>
> > > Error info:
> > >   Expected: instance of <Project>
> > >   But was:  <Castle.Proxies.ActivitySubjectProxy>
>
> > --
> > 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.

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