Sorry if this has been asked before, I did a search but couldn't find anything.
Is it possible to execute inline sql in nHibernate? I have something like this which I would like to run against the dB:
_session.CreateSQLQuery(
@"update things
set defaultThing = 0 where parentId = :parentId AND thingId <> :thingId")
.SetInt32("parentId ", parent.Id)
.SetInt32("thingId", thing.Id)
;
I suppose I could loop through a bunch of 'things' and set the defaultThing setting to false then call _session.Update(thing)
, but if I can do it how I outlined above, that would be great.
Yes, just use ExecuteUpdate()
on that query. It's the equivalent of IDbCommand.ExecuteNonQuery()
.
As kay mentioned, you can use HQL too. Check 12.3. DML-style operations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With