How to use predicates with LINQ for a CRM 2011 query

I am trying to use linqkit for Predicate. Getting the following code when I try to compile.

public void TestPredicate(Guid[] productIds)
{
    var predicate = PredicateBuilder.False<Product>();
    foreach (var productId in productIds)
    {
        var tempGuid = productId;
        predicate = predicate.Or(p => p.ProductId== tempGuid);
    }
}

    var query = from p in context.CreateQuery("product")
            .AsExpandable().Where(predicate) select p;
}

      

Error 1: "System.Linq.IQueryable" does not contain "Where" definition and no better overloading method. 'System.Linq.Queryable.Where (System.Linq.IQueryable, System.Linq.Expressions.Expression>)' has some invalid arguments

Error 2 Argument 2: Cannot convert from 'System.Linq.Expressions.Expression>' to 'System.Linq.Expressionions.Expression>

Please suggest me what I need to fix this.

thank

+3


source to share


2 answers


I believe you are using Dynamics CRM. Therefore, the following should work for you.



var query = from p in context.ProductSet
        .AsExpandable().Where(predicate) select p;

      

+3


source


Have you tried something like this?



var query = context.Products.AsExpandable().Where(predicate);

      

0


source







All Articles