Search code examples
c#nhibernatefluent-nhibernate

How can i get NHibernate to give me the SQL it would generate for an insert / update instead of executing it?


I'm using NHibernate to map some very simple entities to three tables.

My program needs to have a mode where it outputs the SQL it would execute to insert or update these tables, so that the SQL can be saved to a script file, to be later executed manually.

This is similar to this question (which has a very nice answer): How can I have NHibernate only generate the SQL without executing it?

Only that question is about SELECT, I need kind of the same but for INSERT / UPDATE. This also needs to be dynamic because it depends on a user option. I mean, when my program does:

        session.Save(entity);

sometimes I need that to hit the db and sometimes I need it to output the SQL it would execute.

Is this at all possible?


Solution

  • This is not possible unfortunately.