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 に答える