We do this quite quite a lot. In your domain object just have a
property called Self which returns itself through the correct
interface:
public virtual YourType Self
{
get { return this; }
}
then you can always refer like this:
var myProperObj = myProxiedObject.Self;
which goes back up the inheritance tree and now can be cast as
expected.
On Dec 18, 12:19 am, 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].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.