If someone could please help me convert the following SQL to nhibernate linq to QueryOver API, I would be greatly appreciative.
SELECT p.ManufacturerName as Name, sum(ps.QtyAvail) as QuantityAvailable
from Product p
inner join (select ProductId, QtyAvail
from ProductStats ps
where ps.QtyAvail > 0) ps on p.ProductId = ps.ProductId
where ltrim(rtrim(isnull(p.ManufacturerName, ''))) <> ''
group by p.ManufacturerName
order by Name
This is the only thing that I have so far that compiles and runs.
var o = Session
.Query<Product>()
.Where(p => p.ManufacturerName != null && p.ManufacturerName.Trim() != string.Empty)
.Join(Session.Query<ProductStats>().Where(ps => ps.QtyAvail > 0), product => product.ProductId, stats => stats.ProductStatId,
(product, stats) => new { Name = product.ManufacturerName, QuantityAvailable = stats.QtyAvail })
.GroupBy(q => q.Name)
.Select(g => new { Name = g.Key, QuantityAvailable = g.Sum(v => v.QuantityAvailable) });
Thanks in advance.
selects with QueryOver, just mapped tables. You'll have to use HQL or raw SQL.