使用NHibernate更新前n个 [英] Update Top n using NHibernate

查看:72
本文介绍了使用NHibernate更新前n个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使NHibernate产生此t-sql请求?

How can I make NHibernate produce this t-sql request ?

更新前(n)个任务 设置修改 条件

Update top (n) Tasks set MODIFICATIONS where CONDITION

我不想进行交易+批量更新.

I don't want to do a Transaction + batch update.

推荐答案

请检查以下内容:

引用的代码段:

ISession session = sessionFactory.OpenSession();
ITransaction tx = session.BeginTransaction();
string hqlVersionedUpdate = "update versioned Customer set name = :newName where name = :oldName";
int updatedEntities = s.CreateQuery( hqlUpdate )
        .SetString( "newName", newName )
        .SetString( "oldName", oldName )
        .ExecuteUpdate();
tx.Commit();
session.Close();

因此,通过这种方式,我们可以使用HQL定义UPDATE(使用我们的域模型)并直接在DB端一次执行udpate

So, this way, we can defin UPDATE with HQL (using our domain model) and executing the udpate directly at once on DB side

注意:有关更多详细信息,请参见此博客文章: NHibernate –可执行DML by Ayende

NOTE: for more details also check this blog post: NHibernate – Executable DML by Ayende

这篇关于使用NHibernate更新前n个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆