简体   繁体   English

单个NHibernate HQL语句中的多个更新

[英]Multiple updates in a single NHibernate HQL statement

I would like to execute the following two statements at once with NHibernate HQL: 我想使用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. 但是我总是得到一个QuerySyntaxException。 Isn't this possible with NHibernate 3.3.1 or am I doing something wrong? 使用NHibernate 3.3.1可行吗?还是我做错了什么?

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? 在我看来,这行得通吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM