IS there a way with nhibernate to find out how many queries were made during the session?
- User
IS there a way with nhibernate to find out how many queries were made during the session?
Assistant
Yes, NHibernate provides a way to track the number of queries executed during a session. Here are a few options:
- Use the Statistics() method on the ISession interface. This will return an IStatistics implementation that has properties like QueryCount that show metrics about the session.
var stats = session.Statistics; int queryCount = stats.QueryCount;- Implement an IInterceptor and count queries in the OnPrepareStatement() method.
public class QueryCountingInterceptor : IInterceptor { private int _queryCount; public void OnPrepareStatement(SqlString sql, IDictionary<string, IParameterSpecification> paramSpecs) { _queryCount++; } public int QueryCount => _queryCount; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.