I'm trying to use SUM
to add an attribute of an entity using HQL
of NHibernate
, but every time I run query
returns empty.
I'm following the example here but I still could not do it. How to do this?
I'm trying like this.
public IList<Conta> findAllContasReceber()
{
ISession _session = getSession();
String SQL = "SELECT c.cliente, c.historico, c.dtLancamento, c.dtVencimento, SUM(c.valorPagar), " +
"c.valorAcrescimo, c.valorFinal, c.dtPagamento, c.tipoConta, c.planoConta, c.status, c.venda " +
"FROM Conta c WHERE (c.tipoConta = 1) AND (c.status = 0) GROUP BY c.dtVencimento, c.cliente ORDER BY c.dtVencimento";
IList<Conta> list = _session.CreateQuery(SQL).List<Conta>();
return list;
}
Entity
[Serializable]
public class Conta
{
public virtual long id { set; get; }
public virtual Cliente cliente { set; get; }
public virtual String historico { set; get; }
public virtual DateTime dtLancamento { set; get; }
public virtual DateTime dtVencimento { set; get; }
public virtual decimal valorPagar { set; get; } //total vendas
public virtual decimal valorAcrescimo { set; get; } //total acrescimo
public virtual decimal valorFinal { set; get; } //total pagar
public virtual DateTime dtPagamento { set; get; }
public virtual int tipoConta { set; get; } //1 receber, 2 pagar
public virtual PlanoDeConta planoConta { set; get; }
public virtual int status { set; get; } //0 ativa, 1 fechada, 2 cancelada, 3 aguardando pagamento
public virtual Venda venda { set; get; }
public Conta()
{
}
}