No, that is the edge case that this exposes, the issue is that the payment variable is the proxy, and we can't keep identity reference between that while transforming the type.
On Mon, Jan 25, 2010 at 12:44 AM, Diego Mijelshon <[email protected]>wrote: > I'm curious, is it possible to make this slightly different test work? > > public void GhostPropertyMaintainIdentityMap() > { > using (ISession s = OpenSession()) > { > var payment = s.Load<Payment>(1); > var order = s.Get<Order>(1); > > Assert.AreSame(order.Payment, payment); > } > } > > > Diego > > > > On Sun, Jan 24, 2010 at 18:45, Ayende Rahien <[email protected]> wrote: > >> Okay, >> I just committed initial support for this. >> Given the following mapping: >> <class name="Order" table="Orders"> >> <id name="Id"> >> <generator class="assigned" /> >> </id> >> <many-to-one name="Payment" *force-load-on-property-access="true"*/> >> </class> >> >> >> <class name="Payment" abstract="true"> >> <id name="Id"> >> <generator class="assigned" /> >> </id> >> <discriminator column="Type" type="System.String"/> >> <subclass name="WireTransfer" discriminator-value="WT"> >> </subclass> >> <subclass name="CreditCard" discriminator-value="CC"> >> >> </subclass> >> >> </class> >> >> The following test will pass: >> >> [Test] >> public void CanGetActualValueFromLazyManyToOne() >> { >> using (ISession s = OpenSession()) >> { >> var order = s.Get<Order>(1); >> >> Assert.IsTrue(order.Payment is WireTransfer); >> } >> } >> >> There is one problem, though, and that is the identity map. >> >> public void GhostPropertyMaintainIdentityMap() >> { >> using (ISession s = OpenSession()) >> { >> var order = s.Get<Order>(1); >> >> Assert.AreSame(order.Payment, s.Load<Payment>(1)); >> } >> } >> >> This seems to all works. >> >> Thoughts? >> >> BTW, I really don't like the force-load-on-property-access, how about call >> it ghost="false" ? >> >> On Thu, Dec 31, 2009 at 11:32 AM, Ayende Rahien <[email protected]>wrote: >> >>> I am trying to figure out if we can support the following: >>> >>> class Comment >>> { >>> public virtual Post Post {get;set;} >>> } >>> >>> class Post {} >>> class Article : Post {} >>> >>> And *not* generate a PostProxy for the property, but instead detect the >>> property access, force a load to return the correct type. >>> We can do it right now by specifying lazy=false, but that pre-load the >>> entity, while I would like to try to get it to load only on access time. >>> >>> There are several potential problems with this: >>> a) we need to replace the reference on first access, which means that the >>> _parent_ must be a proxy as well. >>> b) we disallow field access entirely. >>> c) identity map issues? >>> >>> other thoughts? >>> >> >> >
