Automatic profiling / unit testing of NHibernate behavior

I have been using NHibernate quite intensively for several months, and I find it very powerful, but for me it is a tool that can sometimes hurt you. I have had many situations where relatively simple changes in the mapping, in the LINQ query, or in any code using my objects, lead to unexpected behavior. My most “impressive success” is a read operation that removes and inserts N + 1 just because I sorted a collection of components in code instead of a database.

Thanks to NHProf, I can track some of these problems, but I feel like I can’t be sure that after refactoring or a little requirement, my level of access to data still behaves correctly and efficiently . Manual testing / profiling after each change is somehow painful. What I'm expecting here is a unit test way of NHibernate's behavior under the hood , that is, what kind of SQL is generated, how many queries are executed, how many loaded objects, the number of connected tables, etc.

I know that this may differ slightly from the main purpose of ORM, but for applications that should work well, this low-level knowledge seems more important to me than abstraction.

Are there any implementations like this idea? How can I automate the profiling of my NHibernate application?

+6
source share
1 answer

Something I used for this purpose, Statistics .

You can get an IStatistics instance from your factory session and get lots of performance metrics, including the number of requests completed, cache misses, runtimes, and more.

With this, you can set up modulation / integration tests that make adequate calls and verify that these indicators are in the expected control parameters.

+6
source

Source: https://habr.com/ru/post/888853/


All Articles