i has the function:
private IEnumerable<Promotion> MatchesKeyword(IEnumerable<Promotion> list, String keyword)
{
...snip...
}
which now executes the LINQ query:
private IEnumerable<Promotion> MatchesKeyword(IEnumerable<Promotion> list, String keyword)
{
return list.Where(item => item.Name.ContainsText(keyword)
|| item.Description.ContainsText(keyword)
...snip...
);
}
This code works quite well.
But I need to convert it to use PredicateBuilder:
private IEnumerable<Promotion> MatchesKeyword(IEnumerable<Promotion> list, String keyword)
{
var predicate = PredicateBuilder.False<Promotion>();
predicate = predicate.Or(item => item.Name.ContainsText(keyword)
|| item.Description.ContainsText(keyword)
...snip...
);
return list.Where(predicate);
}
Which, oddly enough, does not compile. Line of failure:
return list.Where(predicate);
You can choose the errors:
- Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable'
- 'System.Collections.Generic.IEnumerable' does not contain a definition for “Where” and the best method of extension overloading. "System.Linq.Enumerable.Where (System.Collections.Generic.IEnumerable, System.Func)" has some invalid arguments
- 2: 'System.Linq.Expressions.Expression > ' 'System.Func'
? IEnumerable , IEnumerable .
, PredicateBuilder, any .
, PredicateBuilder:
private IEnumerable<Promotion> MatchesKeyword(IEnumerable<Promotion> list, String keyword)
{
var predicate = PredicateBuilder.False<Promotion>();
predicate = predicate.Or(item => item.Name.ContainsText(keyword)
|| item.Description.ContainsText(keyword)
...snip...
);
DateTime dt = TryStrToDate(keyword);
if (dt)
predicate = predicate.Or(item => item.PromotionDate == dt);
return list.Where(predicate);
}
... , , , , .