Hibernate version:
1.2.0GA
Name and version of the database you are using:
SQL 2005
Is there a better way to handle this type of SqlProjection:
Code:
private IProjection CalculatedDistanceProjection(ICDBSearchCriteria criteria)
{
string[] columnAliases = {"distance"};
IType[] types = {NHibernateUtil.Int32};
string sqlCalculateDistance =
String.Format("common.calculatedistance({0},{1},{2},{3}) as distance", "postalCode",
SetNullStringIfEmpty(criteria.PostalCode), SetNullStringIfEmpty(criteria.City),
SetNullStringIfEmpty(criteria.Statecode));
return Projections.SqlProjection(sqlCalculateDistance, columnAliases, types);
}
This function is called by:
Code:
projectionList.Add(CalculatedDistanceProjection(criteria), "Distance");
I tried subclassing the dialect and using register function within the constructor but I couldn't get it to work using ICriteria nor could I find any examples of using a SQL function within a projection.
This does work as shown, but it's dependent on supplying the "postalCode" field name as a string instead of a mapped field.