I would like to extend the expression parameter in my method to add my own filters. I am trying to do something like below, but the syntax is wrong:
public static IList<MyPage> DoSomething<T>(Expression<Func<T, bool>> predicate)
{
return DataStore().GetPages().Where(p => p.PublishDate < DateTime.Now && predicate)
}
The compiler is complaining is complaining in Visual Studio 2012 with this error:
Error 29 Operator '&&' cannot be applied to operands of type '
bool' and 'System.Linq.Expressions.Expression<System.Func<T,bool>>'
Would extending the predicate first be better then feed if back as .Where(predicate)? How would you do that?
Would extending the predicate first be better then feed if back as .Where(predicate)? How would you do that?
Yes, and exactly like that, if I understand what you are suggesting correctly. You can chain .Where() like this:
public static IList<MyPage> DoSomething<T>(Expression<Func<T, bool>> predicate)
{
return DataStore().GetPages().Where(p => p.PublishDate < DateTime.Now).Where(predicate);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With