Search code examples
c#nhibernatehibernatenhibernate-mappinghbm

How to use Dynamic Instantiation with ICriteria in Nhibernate?


I know that you can do this easily with HQL using the following syntax:

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

In this example, the ItemRow need not be a persistent class that has its own mapping class.

But how can we accomplish the same using ICriteria?


Solution

  • Pretty sure that is equivalent to...

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