Query return problem

Asked

Viewed 64 times

0

I have a problem with my query return.

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_current as col_0_0_, MAX(rota0_.Dtlancamento) as col_1_0_ from [Rota] rota0_group by rota0_.Id ]

1 answer

0

The problem is that the field being grouped is not being returned in the search and also the opposite the field being returned in the search. For example the correct 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 that one link about group by, there are several examples of selects with many columns.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.