How can I have NHibernate only generate the SQL without executing it?

You can get the generated sql queries without execution with the following methods: For the NHibernate.Linq queries: public String GetGeneratedSql(System.Linq.IQueryable queryable, ISession session) { var sessionImp = (ISessionImplementor) session; var nhLinqExpression = new NhLinqExpression(queryable.Expression, sessionImp.Factory); var translatorFactory = new ASTQueryTranslatorFactory(); var translators = translatorFactory.CreateQueryTranslators(nhLinqExpression, null, false, sessionImp.EnabledFilters, sessionImp.Factory); return translators[0].SQLString; } For Criteria queries: public … Read more