I'm using entity framework 6.1.3 and .net framework 4.5.1 with C# lang.
What I want to do is; I want to combine expressions with if-else statements.
Here is my expression
Expression<Func<Article, bool>> expression =
q => (!newsDayStart.HasValue || q.PublishedOn >= newsDayStart) &&
(!newsDayEnd.HasValue || q.PublishedOn <= newsDayEnd) &&
(!categoryId.HasValue || q.CategoryId == categoryId.Value) &&
(string.IsNullOrEmpty(searchText) || q.Title.Contains(searchText) &&
(!isActive != null || q.IsActive == isActive.Value));
to
Expression<Func<Article, bool>> expression = ......;
if ( newsDayStart.HasValue )
{
//Obviosly += this statement will not work.
expression += q => q.PublishedOn > = newsDayStart
}
//TODO write other if else statements...
//Send expression
_context.Articles.Where(expression).Count();