tags:

views:

37

answers:

1

Hi, Having trouble with an HQL query. If I remove the avg(..) from it it will return all of the empty weights, so the trouble is with the avg function. It seems clear in the Nhibernate docs that I can perform an aggregate function on the select item like this. Is my problem something to do with query.ToList not liking to return a list of one thing? I just get the "Could not execute query[SQL:SQL not available] message.

 public List<T> HQLQuery<T>(string HQL) //in UnitOfWork
    {
        var query = session.CreateQuery(HQL);
        return query.List<T>().ToList<T>();


    }

   public static float estimateTruckEmptyWeight(int vehicleID)
    {
        UnitOfWork uow = new UnitOfWork();
        List<float> results = uow.HQLQuery<float>("select avg(ev.EmptyWeight) from FieldSystemCore.Domain.EmptyVehicle ev where ev.Vehicle.ID = '" + vehicleID + "'");
        return results[0];

    }
+1  A: 

The trouble turned out to be because avg returns double in Nhibernate, not float.

I wish the exception gave me a clue that this was the case.

IsaacB
That's the DB provider, not NH
Diego Mijelshon
Not sure about that, everything in the database is recorded in floats. Documentation specifically said avg(..) always returns double.
IsaacB