c# - NHibernate Db Calls made in a web session -
i have started working on project using nhibernate orm tool.i read contextual session in nhibernate , understood idea behind it. have doubt in 1 area,
let's say, have employee domain , in http call,i calling repository getting employee id =1 , 3 times.
employee employee = _employeerepository.getemployee(1);
case 1: 1 db call case 2: 3 db calls.
please guide me on this.
rgds sandy
it depends on setup.
the first level cache hit db once against each session object use query with. if there single session shared repository.. 1 db call made. however, if each call repository causes more 1 session created, you'll multiple calls. default.
if second level cache enabled, each session created via sessionfactory share above properties. meaning, if have multiple repositories multiple session's came same sessionfactory instance.. loading same employee both repositories cause single db call.
there information in post - related hibernate, basic principles still apply nhibernate.
i recommend enable second level cache (we use syscache2) in web environment.. can guarantee session's share cached objects within single request (assuming of course, session lifetime management per-request.. should be..).
Comments
Post a Comment