如何在Nhibernate中使用ICriteria的动态实例化?

时间:2010-02-18 17:07:59

标签: c# nhibernate hibernate nhibernate-mapping hbm

我知道您可以使用以下语法轻松地使用HQL执行此操作:

"select new ItemRow(item.id, item.name) from ..."

在此示例中,ItemRow不必是具有自己的映射类的持久化类。

但我们如何使用ICriteria完成同样的工作?

1 个答案:

答案 0 :(得分:1)

非常确定这相当于......

.SetProjection(Projections.ProjectionList()
    .Add(Projections.Property("item.id"), "id")
    .Add(Projections.Property("item.name"), "name"))
.SetResultTransformer(Transformers.AliasToBean<ItemRow>())
.List<ItemRow>();