jagid wrote:
You need to navigating the relationships between your entities:
Code:
var groups = session.CreateCriteria(typeof (Model.ProductGroup), "pg")
.CreateAlias("pg.ProductCategories", "pc")
.CreateAlias("pc.Products", "p")
.Add(new GtExpression("p.Nitrogen", 10D))
.List <Model.ProductGroup>();
If you are using field mappings for your collections then you'll need to refer to the field because NHibernate does not know about the properties:
Code:
var groups = session.CreateCriteria(typeof (Model.ProductGroup), "pg")
.CreateAlias("pg._productCategories", "pc")
.CreateAlias("pc._products", "p")
.Add(new GtExpression("p.Nitrogen", 10D))
.List <Model.ProductGroup>();
Thanks, I have worked this out, the trick was create alias and joins:
.CreateAlias("ProductCategories", "pc", JoinType.InnerJoin)
.CreateAlias("pc.Products", "p", JoinType.LeftOuterJoin)
Then set the result transformer to be unique:
.SetResultTransformer(new DistinctRootEntityResultTransformer());
And it all works :). I am starting to like nHibernate now. Once I figure these things out.
Cheers
Stefan