NHibernate的 - 无负载实体更新单场? [英] Nhibernate - Update single field without loading entity?

查看:146
本文介绍了NHibernate的 - 无负载实体更新单场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里用户得到的产品列表的使用情况,并且可以选择多个产品和主动或禁用它们。

I have a use case where a user gets a list of products, and can select multiple products and active or deactivate them.

此列表的模式是不可变的和我有一个资料库这需要应该取消他们所有的模型的列表。

The model for this list is immutable, and I have a repository which takes a list of the model that should deactivate them all.

我有另一个完整的产品编辑模型,但我宁愿没有装载数百那些简单地改变一个栏位。

I do have another full product editing model, but I'd rather not have to load up hundreds of those to simply change one column.

我使用Session.CreateQuery concidering,但有没有更好的方式来acomplish呢?

I'm concidering using Session.CreateQuery, but is there a better way to acomplish this?

推荐答案

HQL是要走的路。

Session.CreateQuery("update Product set Active = :active where id in (:ids)")
       .SetParameter("active", active)
       .SetParameterList("ids", listOfSelectedProductIds)
       .ExecuteUpdate();

这篇关于NHibernate的 - 无负载实体更新单场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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