I am creating auto-synchronizing collection, and for that I need
references to the same instance. If I do for example:

invoice.lineItems.Add(item);
item.invoice = invoice;

I would not have this issue, but since I "must" have auto-synch
collection, I need to get the reference to the proxy. Unfortunatelly,
in this code
collection.Owner is not a proxy, but original proxied object. I can
get around that if collection fetched has at least one member, because
I can look up inverse property in the item, but if there are no items
in the collection, I get above mentioned problem.

  public void OnInitializeCollection(InitializeCollectionEvent @event)
  {

              IPersistentCollection collection = @event.Collection;
            ISessionImplementor source = @event.Session;
            CollectionEntry ce =
source.PersistenceContext.GetCollectionEntry(collection);
            bool wasInitialized = collection.WasInitialized;

            defaultListener.OnInitializeCollection(@event);

            if (!wasInitialized)
            {
                string role = ce.LoadedPersister.Role;
                string propertyName = role.Substring(role.LastIndexOf
(".") + 1);
                PropertyInfo pi = collection.Owner.GetType
().GetProperty(propertyName);

On Nov 22, 10:21 am, "Ken Egozi" <[EMAIL PROTECTED]> wrote:
> I'd think that ReferenceEquels is not appropriate here.
> 'equality' in terms of persisted objects, is either through the PK (for
> entities) or the combination of all properties (for Value Objects).
> It's perfectly allright imo for a DAL of any kind to represent the exact
> same DB row in two actual in-memory objects.
>
>
>
> On Sat, Nov 22, 2008 at 6:13 PM, epitka <[EMAIL PROTECTED]> wrote:
>
> > ... proxied class. I am running in situation that I need to get
> > reference to instance of a proxy when I have reference to a proxied
> > object. I am adding a LoadCollection listener, and collection.Owner is
> > a proxied class and instance of owner is proxy, so when I do
> > bidirectional relationship synchronization this might fail
>
> > Assert.IsTrue(ReferenceEquals(invoice, invoice.lineItems[1].invoice)
>
> > because the "invoice" is a proxy and invoice.lineItems[1].invoice is
> > the instance of the collection.Owner. Since I have real class I wonder
> > if I could look up somehow what is the proxy instance for it.
>
> --
> Ken 
> Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.comhttp://www.castleproject.orghttp://www.gotfriends.co.il
--~--~---------~--~----~------------~-------~--~----~
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