When using CreateSqlQuery, is it possible to retrieve an ordered list of the returned column names? Using .List only returns a list of the object values, not the column aliases.
A:
If you are returning info from a single table you don't need column names since it would match with an entity class in your model, I imagine that you're retrieving fields from different tables and you don't have a entity defined for that.
You may define a new entity for the result of this query using the "join" feature
http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#mapping-declaration-join
Claudio Redi
2010-02-02 00:56:06
A:
If you apply an IResultTransformer
to your query via SetResultTransformer()
, it will be called with two lists containing column names and values.
There are several existing transformers in namespace NHibernate.Transform, such as:
AliasToEntityMapResultTransformer
Creates a map from column names to values for each row.AliasToBeanResultTransformer
Creates an object of the nominated type per row and sets its properties with the value from the column of the same name.ToListResultTransformer
Returns a list of values for each row.
Lachlan Roche
2010-03-02 04:38:37