开发者

Executing multiple updates in a single NHibernate HQL statement

I would like to write the following SQL in HQL so it executes as a single statement:

开发者_JAVA百科update child_thingy c
set c.parent_thingy_id = null
where c.common_thingy_id = @common_thingy_id

delete
from parent_thingy p
where p.common_thingy_id = @common_thingy_id

I've translated the SQL to HQL as follows:

update ChildThingy c
set c.ParentThingy = null
where c.CommonThingy = :commonThingy

delete
from ParentThingy p
where c.ParentThingy = :commonThingy

I would like to run this as a single statement, but I can't in a single HQL block using CreateQuery & ExecuteUpdate. I can't run this either in a MultiQuery block and List as I get the following exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at NHibernate.Impl.MultiQueryImpl.AggregateQueriesInformation()
at NHibernate.Impl.MultiQueryImpl.get_Parameters()
at NHibernate.Impl.MultiQueryImpl.CreateCombinedQueryParameters()
at NHibernate.Impl.MultiQueryImpl.List()

I can't seem to find a MultiQuery equivalent of ExecuteUpdate. Any ideas?


Doesn't seem possible (in NH 2.1.2), so had to resort to using CreateSQLQuery and ExecuteUpdate :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜