Skip to content
On this page

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. Postgres type casts :: can be applied to the parameter if needed.

cs
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());
var json = "{ \"answer\": 42 }";
theSession.QueueSqlCommand("insert into data (raw_value) values (?::jsonb)", json);

snippet source | anchor

Released under the MIT License.