Getting a bit stuck on this. Basically I have a method that I want to return a predicate expression that I can use as a Where condition. I think what I need to do is similar to this: http://msdn.microsoft.com/en-us/library/bb882637.aspx but I'm a bit stuck as to what I need to do.
Method:
private static Expression<Func<Conference, bool>> GetSearchPredicate(string keyword, int? venueId, string month, int year)
{
if (!String.IsNullOrEmpty(keyword))
{
// Want the equivilent of .Where(x => (x.Title.Contains(keyword) || x.Description.Contains(keyword)));
}
if (venueId.HasValue)
{
// Some other predicate added...
}
return ??
}
Example Usage:
var predicate = GetSearchPreducate(a,b,c,d);
var x = Conferences.All().Where(predicate);
I need this separation so that I can pass my predicate into my repository and use it in other places.