I'm using NHibernate quite intensively for few months and I find it very powerful, but for me this is the kind of tool that can sometimes hurt you. I had a lot of situations that relatively simple change in mapping, in LINQ query or in any code that use my entities led to unexpected behaviors. My most "spectacular success" is having the read operation that did N+1 deletes and inserts just because I was sorting my components collection in code instead of in the database.
Thanks to NHProf I can track some of issues like this, but I feel I can't be sure that after refactoring or small requirement changes my data access layer still behaves correctly and efficiently. Testing/profiling it manually after each change is somehow painful. What I'll expect here is some kind of way to unit test the NHibernate's behavior under the hood, i.e. what SQL is generated, how many queries are done, how many entities loaded, how many tables joined etc.
I know that it may be a bit off the main ORM purpose, but for applications that need to perform well, that low-level knowledge seems to me to be more important than the abstraction.
Are there any implementations similiar to this idea? How can I automate profiling my NHibernate application?
Something I have used for this purpose is Statistics.
You can get an IStatistics
instance from your session factory, and get lots of performance indicators, including number of queries executed, cache misses, execution times, and many more.
With this, you can set unit/integration tests that perform the adequate calls and verify those indicators are inside the expected reference parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With