-1

对于为以下提到的 SQL 编写 NHibernate QueryOver 等效项,我将不胜感激:

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"
4

1 回答 1

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>();
于 2012-12-17T17:40:43.200 回答