1
I’m trying to use the SUM
to sum an attribute of an entity using HQL
of NHibernate
, but whenever I execute the query
returns empty.
I am following the example here but I still can’t 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()
{
}
}
I believe, because this SQL will not return the data of this query, because, the class would need a Join by aggregation fields like
Cliente
andPlanoDeConta
. Take a test don’t come back a guyConta
returns the pure list to see if it returns any table value, type_session.CreateQuery(SQL).List()
have this option if you have check if it returns values?– novic
@Virgilionovic I believe that C# does not allow returning a pure list as vc flw, it is necessary to inform the type of the list for example:
List<String>
orList<Object>
something like that. I’m just trying to returnList
and asks for an argument.– FernandoPaiva
let me take a look here has a ready example on my pc and I’ll tell you, ok?
– novic
it returns a method without parsing also ie, return type of
List
type-lesssession.CreateQuery("").List()
– novic
@Virgilionovic yes, but in the signature of the method I can not put this return
public List findAllContasReceber()
.– FernandoPaiva
because the return is
System.Collections.IList SqlQuery(string sql);
the correct signature! , first I want to see if it returns something,public System.Collections.IList findAllContasReceber()
– novic
yes, but the
IList
tbm needs to be typed, likeIList<String>
orIList<Object
or as in my caseIList<Conta>
.– FernandoPaiva
Let’s go continue this discussion in chat.
– novic
Ilist this is the correct type, even this is just a test to see if it returns something.!
– novic
@Virgilionovic problem solved, posted the solution. Hug.
– FernandoPaiva