Skip to content

Execute custom SQL in session

Use QueueSqlCommand(string sql, params object[] parameterValues) method to register and execute any custom/arbitrary SQL commands with the underlying unit of work, as part of the batched commands within IDocumentSession. "?" placeholders can be used to denote parameter values.

theSession.QueueSqlCommand("insert into names (name) values ('Jeremy')");
theSession.QueueSqlCommand("insert into names (name) values ('Babu')");
theSession.Store(Target.Random());
theSession.QueueSqlCommand("insert into names (name) values ('Oskar')");
theSession.Store(Target.Random());

snippet source | anchor