Chain LINQ expressions for filtering Example of my method where I am chaining linq expressions based on model values provided:

public async Task&lt;List&lt;HistoryWorkoutExerciseModel&gt;&gt; GetHistoryWorkoutExerciseByFilterAsync(ChartFilterModel model)
{
    Expression&lt;Func&lt;HistoryWorkoutExercise, bool&gt;&gt; baseFilter = x =&gt; true &amp;&amp; x.CreatedBy == model.CreatedBy;
    Expression&lt;Func&lt;HistoryWorkoutExercise, bool&gt;&gt; exerciseFilter = x =&gt; x.ExerciseId == model.ExerciseFilter;
    Expression&lt;Func&lt;HistoryWorkoutExercise, bool&gt;&gt; timeSpanFilter = x =&gt; x.HistoryWorkout.TimeTakenDate &gt;= model.StartDate &amp;&amp; x.HistoryWorkout.TimeTakenDate &lt;= model.EndDate;

    if (model.ExerciseFilter &gt; 0 &amp;&amp; model.DateFilter == 0)
    {
        baseFilter = baseFilter.AndAlso(exerciseFilter);
    }

    if (model.ExerciseFilter == 0 &amp;&amp; model.DateFilter &gt; 0)
    {
        baseFilter = baseFilter.AndAlso(timeSpanFilter);
    }

    if(model.ExerciseFilter &gt; 0 &amp;&amp; model.DateFilter &gt; 0)
    {
        baseFilter = baseFilter.AndAlso(timeSpanFilter).AndAlso(exerciseFilter);
    }

    return _mapper.Map&lt;List&lt;HistoryWorkoutExerciseModel&gt;&gt;(await _repository.GetAsync(baseFilter, x =&gt; x.OrderByDescending(y =&gt; y.HistoryWorkout.TimeTakenDate), "Exercise,HistoryWorkout"));
}


What's the best way to refactor this, as I am not the best fan of if conditional statements? Is there any other specific approach for this?
You have such properties as ExerciseFilter and DateFilter that I guess return respecitively the ExerciseId and (EndDate - StartDate).TotalMinutes or something similar. Thus, I find it would be much easier to understand your filter class if you renamed the ExerciseFilter to ExerciseId and replaced both properties with CanApplyExerciseFilter and CanApplyDateFilter. This would result in a much cleaner code:

if (model.CanApplyExerciseFilter &amp;&amp; !model.CanApplyDateFilter)
{
    baseFilter = baseFilter.AndAlso(exerciseFilter);
}

if (!model.CanApplyExerciseFilter &amp;&amp; model.CanApplyDateFilter)
{
    baseFilter = baseFilter.AndAlso(timeSpanFilter);
}

if (model.CanApplyExerciseFilter &amp;&amp; model.CanApplyDateFilter)
{
    baseFilter = baseFilter.AndAlso(timeSpanFilter).AndAlso(exerciseFilter);
}


which would finally lead us to just two lines of code here:

baseFilter = 
    baseFilter
        .AndAlso(model.CanApplyExerciseFilter ? exerciseFilter : x =&gt; true)
        .AndAlso(model.CanApplyDateFilter ? timeSpanFilter : x =&gt; true);