I have the following domain model:

class User {
   virtual int Id { get; set; }
   virtual int TenantId { get; set; }
   virtual string UserName { get; set; }
   virtual Party Party { get; set; }
}
abstract class Party {
virtual int Id { get; set; }
    abstract Name { get; }
}
class Person : Party {
   virtual string FirstName { get; set; }
   virtual string LastName { get; set; }
   virtual override Name { get { return string.Concat(this.FirstName,
" ", this.LastName); } }
}

A very simple XML mapping with discriminator column is being used.
I've simplified the model above and removed access control btw -
assume everything is public.

Now I'm loading the User and need the Party.Name to be available so
I'm using the following HQL query:

from User u
left join fetch u.Party
where u.TenantId = 16

I am displaying a grid with Id, UserName, Party.Name

The query loads the Parties fine with FirstName and LastName.  I can
see that in NHprof it's loading the two name columns eagerly.

However, when I access the Name property which depends on FirstName
and LastName, it causes the party to be lazy loaded (even though it's
already loaded) and therefore a SELECT N+1 problem.

Using NH 2.0.1 btw.

Any ideas how to stop this lazy load problem?

Cheers,

Chris Smith

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