Problem in returning the query

0

I have a problem with my return from the query.

public IList<Rota> Lista()
        {
        //* string hql = "SELECT * FROM Rota WHERE ORDER BY Km_Atual ASC";
        string hql = "SELECT Km_Atual, MAX(DtLancamento) FROM Rota GROUP BY Id";
        //* string hql = "SELECT p FROM Rota p";
        IQuery query = session.CreateQuery(hql);
        return query.List<Rota>();
        }
  

An exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll but was not handled in user code

     

Additional information: could not execute query

     

[select rota0_.Km_Anal the col_0_0_, MAX (rota0_.DtLancamento) the col_1_0_ from [Rota] rota0_ group by rota0_.Id]

    
asked by anonymous 22.06.2017 / 20:41

1 answer

0

The problem is that the field being grouped is not being returned in the search and also the reverse of the field that is being returned in the search. For example the correct one would be:

SELECT ID, MAX(DTLANCAMENTO) FROM ROTA GROUP BY ID

or

SELECT KM_ATUAL, MAX(DTLANCAMENTO) FROM ROTA GROUP BY KM_ATUAL

You can read about this link about group by , there are several examples of selects with many columns.

    
28.02.2018 / 15:54