2012-04-04 54 views
4

在子查询我有以下这些失败:NHibernate的QueryOver分离标准和任何条款

var subquery = QueryOver.Of<Product>() 
       .Where(x => x.ProductCategories.Any(y => y.Categgory == parameter.Category)); 

我得到的任何说法的错误:

Unrecognised method call: System.Linq.Enumerable:Boolean Any 

如何将更新上述限制为QueryOver?

回答

5
ProductCategory productCategory = null; 
var subquery = QueryOver.Of<Product>() 
    .JoinAlias(product => product.ProductCategories,() => productCategory)    
    .Where(() => productCategory.Category.Id == parameter.Category.Id); 

什么是类别的类型?如果这是一个实体:

productCategory.Category.Id == parameter.Category.Id 

如果这是基础属性:

productCategory.Category == parameter.Category 

是它的许多一对多的关系? (Product and Category)

Category category = null; 
var subquery = QueryOver.Of<Product>() 
    .JoinAlias(product => product.Category,() => category)    
    .Where(() => category.Id == parameter.Category.Id); 
1
ProductCategory productCategory = null; 
var subquery = QueryOver.Of<Product>() 
    .JoinAlias(product => product.ProductCategories,() => productCategory) 
    .Where(Subqueries.WhereExists(CatExistsQuery()) 


private QueryOver<ProductCategory , ProductCategory > CatExistsQuery(<your type> parameter) 
     { 
      ProductCategory _innerCat = null; 

      var query = (QueryOver<ProductCategory , ProductCategory >)Session 
         .QueryOver(() => _innerCat) 
         .Where(() => _productCategory.Id== _innerCat.Id) 
         .And (innerCat.Id == parameter.Category.Id) 

      return query ; 
     }