c# - What does Future() means in NHibernate? -


i'm new nhibernate description ienumerable future(); says following

// summary: //     enumerable when enumerated execute batch of queries in //     single database roundtrip 

just wondering means, description has nothing word 'future'

future allows execute 2 or more sql in single roundtrip, long database supports it.

it's transparent, you'll want use futures whenever possible. if nhibernate can't execute queries in single roundtrip, execute queries in 2 or more, expected.

from http://ayende.com/blog/3979/nhibernate-futures

let take @ following piece of code:

using (var s = sf.opensession()) using (var tx = s.begintransaction()) {     var blogs = s.createcriteria<blog>()         .setmaxresults(30)         .list<blog>();     var countofblogs = s.createcriteria<blog>()         .setprojection(projections.count(projections.id()))         .uniqueresult<int>();      console.writeline("number of blogs: {0}", countofblogs);     foreach (var blog in blogs)     {         console.writeline(blog.title);     }      tx.commit(); } 

this code generate 2 queries database 2 queries database expensive, can see took 114ms data database. can better that, let tell nhibernate free optimization in way likes

using (var s = sf.opensession()) using (var tx = s.begintransaction()) {     var blogs = s.createcriteria<blog>()         .setmaxresults(30)         .future<blog>();     var countofblogs = s.createcriteria<blog>()         .setprojection(projections.count(projections.id()))         .futurevalue<int>();      console.writeline("number of blogs: {0}", countofblogs.value);     foreach (var blog in blogs)     {         console.writeline(blog.title);     }      tx.commit(); } 

instead of going database twice, go once, both queries @ once. speed difference quite dramatic, 80 ms instead of 114 ms, saved 30% of total data access time , total of 34 ms.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -