Quantcast
Channel: Customer FX
Viewing all articles
Browse latest Browse all 981

How to Sum a Collection using Hibernate Criteria and Projections

$
0
0

 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()));
            criteria.SetProjection(repository.PF.Sum("ElapsedUnits"));
            Double units = Convert.ToDouble(criteria.UniqueResult());


Viewing all articles
Browse latest Browse all 981

Trending Articles