NHibernate用于Web应用程序,计算每个请求的延迟加载发生次数 [英] NHibernate for web app, count amount of lazy loading occurrences per request

查看:44
本文介绍了NHibernate用于Web应用程序,计算每个请求的延迟加载发生次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Web应用程序,并默认使用延迟加载.我希望应用程序继续运行,即使我忘记"(或故意这样做)以加载某些子实体.这将使应用程序足够健壮,从而避免NullReferenceException.

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.

但是-我确实想统计一下延迟加载发生的次数,如果达到某个阈值则将其记录下来(例如,如果单页渲染使用了超过10个延迟加载,我想写一条WARN消息记录并监视它,以了解瓶颈和天真的实现.

BUT - I do want to count, somehow, the number of times lazy loading happened 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?

推荐答案

我建议您实施每页休眠请求的监控,由Ayende Rahien在他的博客中介绍.它使您可以了解页面懒惰加载的位置.通常,您可以通过对每个页面的命中进行排序,来查明延迟加载对象的页面.

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.

它在您的项目中需要log4net,但我认为这是一件好事:)

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

这篇关于NHibernate用于Web应用程序,计算每个请求的延迟加载发生次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆