-1

I would appreciate some help on writing the NHibernate QueryOver equivalent for the below mentioned SQL:

select sum(s.StudentCount),sum(w.TotalEarningsAmount),
avg(w.TotalEarningsAmount),count(w.TotalEarningsAmount) 
from School s inner join s.Earnings w where s.Active = 1"
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
hegdesachin
  • 285
  • 1
  • 2
  • 9

1 Answers1

3
Earning w = null; //alias variable
Dto dto = null; //make a dto object

var dtoList = Session.QueryOver<School>()
    .JoinAlias(x => x.Earnings, () => w)
    .Where(x => x.isActive)
    .SelectList(list => list
        .SelectSum(x => x.StudentCount).WithAlias(() => dto.StudentCountSum)
        .SelectSum(() => w.TotalEarningsAmount).WithAlias(() => dto.TotalEarningsAmountSum)
        .SelectAvg(() => w.TotalEarningsAmount).WithAlias(() => dto.TotalEarningsAmountAvg)
        .SelectCount(() => w.TotalEarningsAmount).WithAlias(() => dto.TotalEarningsAmountCount))
    .TransformUsing(Transformers.AlaisToBean<Dto>())
    .List<Dto>();
dotjoe
  • 26,242
  • 5
  • 63
  • 77