开发者

NHibernate for web app, count amount of lazy loading occurrences per request

开发者 https://www.devze.com 2023-01-18 22:45 出处:网络
I\'m building a web application and using lazy-loading as default. I would like the application to keep going even if I \"forgot\" (or did it by purpose) to load some sub-entities. This will make the

I'm building a web application and using lazy-loading as default. I would like the application to keep going even if I "forgot" (or did it by purpose) to load some sub-entities. This will make the application robust enough to avoid NullReferenceException.

BUT - I do want to count, somehow, the number of times lazy loading ha开发者_开发问答ppened and log it if some threshold reached (for example, if single page rendering used more than 10 lazy loading, I would like to write a WARN message to my log and monitor it, to understand bottlenecks and naive implementation).

Is there a way to easily pull it off somehow?


NHProf monitors that, among other things.

It's commercial, but it's a great tool for working with NH.


I'd recommend you implement the monitoring of nhibernate requests per page as presented by Ayende Rahien on his blog. It allows you to get an idea of where your pages are lazy loading the most. You can usually pinpoint the pages where the objects are lazy loaded by sorting the hits to the database for each page.

It requires log4net in your project but i'd consider this a good thing :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号