Home
Options

Help required with PredicateBuilder using "Any" Clause

I need to use predicatebuilder to build my dynamic linqs for iqueryable
What I need is dynamic Linq equivalent of:
_dataContextInstance.Items.Where(p=>p.ItemNames.Any(q=>q.Name.Contains("Test")));

What I have:
var q1= _dataContextInstance.Items.AsQueryable();
var predicate = PredicateBuilder.True();
var innerPredicate = PredicateBuilder.True();
string srch = "Test";
innerPredicate = innerPredicate.And(p => p.name.Contains(srch));
predicate = predicate.And(l => l.ItemNames.Any(innerPredicate.Compile()));
var p1 = PredicateBuilder.True();
p1.And(predicate.Expand());
q1.Where(p1);
var results = q1.ToList();

The results list doesnt seem to get the right data. It is getting all the items. As good as the where clause is not being applied. What am I doing wrong. Any help is greatly appreciated. I am going crazy trying to get IQueryable to work with Dynamic Linq for "Any" clause with "Where" condition combined together like my case.
Sign In or Register to comment.