tags:

views:

38

answers:

2

Hello All ,

I have the following entities

public class Category 
{
      Id
      Name
}
public class Product 
{
      Id
      Name
      List<Category> list;
}

what I want to do is get all the product by category name using nHibernate

any help will be appreciated

Thanks in Advance

+2  A: 

Easiest way - to use Linq to nhibernate.

Would look like this:

public void GetProductsByCategoryName(string categoryName){
  Session.Linq<Product>(x=>x.list.Any(z=>z.Name=categoryName));
}
Arnis L.
Thank you Mr.Arnis
Amira Elsayed
@Amira if it helped - just accept it as an answer. :)
Arnis L.
A: 

Thank you for help

i have solved the problem using Join , I didn't fine NHibernate.Linq.dll in the version that I have and I have served the Internet to download it

My Solution is

public IList<Product> GetAllProductsByCategoryName(string name)
{
    return Session.CreateQuery("from Product p left join fetch p.Categories c where c.Name = :name").SetParameter("name", name).List<Product>();

}

Thank you again

Amira Elsayed