Hi,
I'm using Sharp Architecture for an MVC application and I'm trying to generate a nhibernate criterion query for the following SQL:
select top 10 p.* from Tab1 p
join Tab2 v on p.Id = v.Tab1Fk
join Tab3 sbu on v.Id = sbu.Tab2Fk
where sbu.DateTime >= 12/12/2002 00:00:00
group by p.Id, p.Name, p.CoCode, p.CuCode, p.StCode, p.ParentFk, p.LastGenerated
order by COUNT(sbu.Id) desc
Currently I've got:
var crit = Session.CreateCriteria<Tab1>();
crit.SetMaxResults(numberOfRecords);
crit.CreateCriteria("Tab2", "v", JoinType.InnerJoin)
.CreateCriteria("Tab3", "sbu", JoinType.InnerJoin)
.Add(Restrictions.Ge("sbu.DateTime", since))
.AddOrder(Order.Desc(Projections.Count("sbu.Id")));
return crit.List<Tab1>();
But it throws errors, can anyone help?