NHibernate QueryOver with ManytoMany

I study QueryOver, but I cannot figure out in my life how to make simple answers to many.

I wrote the following:

var result = Session.CreateCriteria(typeof (Product)) .CreateAlias("Categories", "categories") .Add(Property.ForName("categories.Id").Eq(categoryId)) .List<Product>(); 

This gives the desired result. I basically

Product> ProductCategory <Category

ProductCategory has only ProductId / CategoryId, and I'm trying to select all products of a certain category.

I don't know where to start trying to do this with a query.

+6
nhibernate queryover
source share
1 answer

In the end, I decided this after much perseverance.

  var result = Session.QueryOver<Product>() .Right.JoinQueryOver<Category>(x => x.Categories) .Where(c => c.Id == categoryId) .List(); 

What a mission :)

+13
source share

All Articles