5

我在子查询中有以下失败:

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

我收到 Any 语句的错误:

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

我将如何更新 QueryOver 的上述限制?

4

2 回答 2

6
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

是多对多的关系吗?(产品和类别)

Category category = null;
var subquery = QueryOver.Of<Product>()
  .JoinAlias(product => product.Category, () => category)            
  .Where(() => category.Id == parameter.Category.Id);
于 2012-04-04T12:01:52.497 回答
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 ;
        }
于 2012-04-04T12:07:46.577 回答