How to use predicates with LINQ to query CRM 2011

242 views Asked by At

I am trying to use linqkit to Predicate. Getting following code when I am trying 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 a definition for 'Where' and the best extension method overload '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.Expressions.Expression>

Please suggest me what I need to do fix it.

Thanks

2

There are 2 answers

0
Scorpion On BEST ANSWER

I believe you are using Dynamics CRM. So following should work for you.

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

Did you try doing something like this?

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