PredicateBuilder について質問があります。これを解決する方法についてアドバイスをいただければ幸いです。これを説明しようと思います。
キーワードで商品を探すケースがあります。各キーワードはキーワード グループに属しているため、実際のデータは次のようになります。
KeywordGroup / キーワード
タイプ - チェーン/
タイプ - ブレスレット/
カラー - パープル/
カラー - グリーン
今、私は次の結果を得たいと思っています:
それぞれの異なる KeywordGroup の間には OR が必要です。KeywordGroup 内の各キーワードの間には AND が必要です。
たとえば、ユーザーは紫または緑のブレスレットのみを検索したいと考えています。
これはこの PredicateBuilder で可能ですか?
これは私がこれまでに持っているものです:
================================
/// <summary>
    /// Search for products
    /// </summary>
    /// <param name="itemsPerPage"></param>
    /// <returns></returns>
    public List<Product> SearchProducts(int from, int max, string sorting, List<Keyword> filter, out int totalitems) {
        try {
            var predicate = PredicateBuilder.True<Product>();
            KeywordGroup previousKeywordGroup = null;
            foreach (Keyword k in filter.OrderBy(g=>g.KeywordGroup.SortOrder)) {
                if (previousKeywordGroup != k.KeywordGroup) {
                    previousKeywordGroup = k.KeywordGroup;
                    predicate = predicate.And(p => p.Keywords.Contains(k));
                }
                else
                    predicate = predicate.Or(p => p.Keywords.Contains(k));
            }
            var products = context.Products.AsExpandable().Where(predicate);
            //var products = from p in context.Products
            //               from k in p.Keywords
            //               where filter.Contains(k)
            //               select p;
            totalitems = products.Distinct().Count();
            if (sorting == "asc")
                return products.Where(x => x.Visible == true).Distinct().Skip(from).Take(max).OrderBy(o => o.SellingPrice).ToList();
            else
                return products.Where(x => x.Visible == true).Distinct().Skip(from).Take(max).OrderByDescending(o => o.SellingPrice).ToList();
        }
        catch (Exception ex) {
            throw ex;
        }
    }
================================
しかし、うまくいきません。
あなたは私を助けることができます?
ありがとう!ダニエル