multi query - NHibernate Multiquery for eager loading without joins -


is possible use multiquery , have 2 hql queries returning 2 different sets of entities 1 of sets used in other , session "fixes" via first level cache?

e.g. scenario (a dumb 1 , solved joins)

public class room {   ...   public virtual iset<bookings> bookings {get;set;}   public virtual bool isavailible {get;set;}   ... }  public class booking {   ... } 

after executing multicriteria 2 hql's:

  1. returning rooms isavailible = true
  2. returning bookings having room has room isavailible

when accessing room result , bookings want them resolved second resultset via firstlevel cache of session , there avoiding n+1.

generally speaking, nhibernate can use cache "combine" results queries executed through multiquery. however, should noted applies cases lazy collections loaded no restrictions whatsoever.

examples:

invoice ialias = null; invoicedetails idalias = null;  // base-query: invoices condition var invoices = session.queryover<invoice>()     .where(i => i.number == "001")     .future<invoice>();  // option 1: still cause n+1 if iterate through invoices, // because doesn't know better var invoicedetails = session.queryover<invoicedetails>()     .joinalias(a => a.invoice, () => ialias)     .where(() => ialias.number == "001")     .future<invoicedetails>();  // option 2: still cause n+1 if iterate through invoices, // because limited possible results using where-condition var invoices2 = session.queryover<invoice>()     .left.joinalias(i => i.details, () => idalias)     .where(i => i.number == "001")     .and(() => idalias.quantity > 5)     .future<invoice>();  // option 3: work without n+1, because don't use filter // -> nhibernate use collection in cache var invoices3 = session.queryover<invoice>()     .left.joinalias(i => i.details, () => idalias)     .where(i => i.number == "001")     .future<invoice>();  foreach (invoice in invoices) {     int count = i.details.count; } 

if comment out 2 of 3 options , execute code, see option 3 prevent n+1, other 2 still load invoicedetails each invoice in loop.

of course simple example , obvious option 3 executed without base-query , still return same result, hope idea.

in case load 2 different sets of entities, i.e. root class different in option 1, "combining" not work.

sorry, if used queryover instead of hql, same rules apply.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -