Select constant/value in icriteria

90 Views Asked by At

Based on a parameter I would like to select a constant value into a field using NHibernate ICriteria

The desired sql could be like

SELECT ID, 'ConstantTile' Title  FROM Table

The only way I can se how its done is using Projections.Conditional which always returns true, but there must be a smarter way

My code for returning a string is:

 public static IProjection GetBoolResult(string desiredResult)
 {
      return Projections.Conditional(Restrictions.Ge("ID",0),
            Projections.Constant(desiredResult, NHibernateUtil.String),
            Projections.Constant("", NHibernateUtil.String));
  }
1

There are 1 best solutions below

0
KeldJ On

The Projections.Alias and Projections.Constant gave the desired result

    public static IProjection GetStringResult(string result,string alias)
    {
        return Projections.Alias(Projections.Constant(result, NHibernateUtil.String), alias);
    }