0
votes

Im working with Nhibernate 3.0 and have problem with QueryOver collection. I have entities

Order{
List<Item> items;
}
Item
{
Product product;
}
Product
{
 String name;
}

Relation between Order and Item is one-to-many. I want to get list of all orders having product with given name using QueryOver< Order> Equivalent of sql:

Select DISTINCT or.* From [Order] or
LEFT JOIN Item it on it.OrderId=or.OrderId
LEFT JOIN Product pr on pr.ProductId=it.ProductId
WHERE p.Name ='NameToSearch'
1

1 Answers

0
votes
Item alias=null;
session.QueryOver<Order>.JoinQueryOver(o=>o.items, ()=>alias)
.JoinQueryOver(i=>i.product)
.Where(p=>p.Name.IsInsensitiveLike("NameToSearch")).
.TransformUsing(Transformers.DistinctRootEntity);

did the job :)