NHibernate - eager fetch a collection -


i'm creating hql query uses eager fetching collections , properties. query:

var result = session.createquery("from match m left join fetch m.user u left join fetch u.profileitems pi m.user.id = :p1")         .setparameter("p1", user.id)         .list<match>().tolist(); 

this works well. using nhprofiler, can see produces following sql query:

select (...) `match` match0_        left outer join `user` user1_          on match0_.userid = user1_.id        left outer join `profileitem` profileite2_          on user1_.id = profileite2_.user_id  match0_.userid =? p0 

now, can iterate on result of match instances or user instances this:

foreach (user u in result.select(m => m.user)) {   // .. } 

... , not hit database again.

however, user object has property not mapped database, isonline. calculation using current date. use property in expression, database hit. example:

int = result.count(m => m.matchinguser.isonline); 

... hit database every user, in case 10 times, using query:

select *   `user` user0_  user0_.id =? p0 

i have 2 main questions:

  1. why this?
  2. how prevent this?

thanks!

unless it's copy&paste error, using different property (matchinguser) 1 fetched (user)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -