Multiple updates in a single NHibernate HQL statement

184 Views Asked by At

I would like to execute the following two statements at once with NHibernate HQL:

update CustomFieldValue set Value = :newVal where Key = 1 and Value = :oldVal;
update CustomFieldValue set Value = :newVal where Key = 1 and Value = :oldVal;

I have created one string and try to update it with

var query = this.Session.CreateQuery(hql);
// ... set parameters
query.ExecuteUpdate();

But I always get a QuerySyntaxException. Isn't this possible with NHibernate 3.3.1 or am I doing something wrong?

1

There are 1 best solutions below

0
Nick DeVore On

I'm struggling to understand why you would want to do this? Am I missing it, or are the commands you want to submit to the database identical?

I'm totally guessing here, but are you really trying to do something like:

update CustomFieldValue set Value = :newVal1 where Key = 1 and Value = :oldVal1;
update CustomFieldValue set Value = :newVal2 where Key = 1 and Value = :oldVal2;

It seems to me, that would work?