How to Sum a Collection using Hibernate Criteria and Projections

 To sum the results of a criteria collection you can use code such as the following, which gets the sum of all ticket activities for a ticket:

            Sage.Platform.RepositoryHelper<Sage.Entity.Interfaces.ITicketActivity>  repository = Sage.Platform.EntityFactory.GetRepositoryHelper<Sage.Entity.Interfaces.ITicketActivity>();
            Sage.Platform.Repository.ICriteria criteria = repository.CreateCriteria();
            criteria.Add(repository.EF.Eq(“Ticket.Id”, ticket.Id.ToString()));
            Double units = Convert.ToDouble(criteria.UniqueResult());


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!