How can this LINQ query using SqlFunctions.Datediff and LINQKit's PredicateBuilder be improved I have this query built using the above, but it feels like it could be improved to make it more concise:

  private IQueryable&lt;Lead&gt; _queryLeadsByHeat(int? ownerUserId, bool warmLeads)
        {
            var predicate = PredicateBuilder.False&lt;Lead&gt;();

            predicate = predicate.Or(x =&gt; x.LeadPool.DecreaseByUnit == (int) DecreaseUnitTime.Day
                                           &amp;&amp;
                                           (
                                               (x.LastHeatValue - SqlFunctions.DateDiff("day", !x.LastContactDate.HasValue
                                                                          ? x.InitialContactDate
                                                                          : x.LastContactDate.Value, DateTime.Today) * x.LeadPool.DecreaseLeadBy) &gt; 0 &amp;&amp; warmLeads ||

                                                (x.LastHeatValue - SqlFunctions.DateDiff("day", !x.LastContactDate.HasValue
                                                                          ? x.InitialContactDate
                                                                          : x.LastContactDate.Value, DateTime.Today)*
                                                x.LeadPool.DecreaseLeadBy) &lt;= 0 &amp;&amp; !warmLeads
                                            )
                                       );

            predicate = predicate.Or(x =&gt; x.LeadPool.DecreaseByUnit == (int)DecreaseUnitTime.Week
                                       &amp;&amp;
                                       (
                                           (x.LastHeatValue - SqlFunctions.DateDiff("week", !x.LastContactDate.HasValue
                                                                      ? x.InitialContactDate
                                                                      : x.LastContactDate.Value, DateTime.Today) * x.LeadPool.DecreaseLeadBy) &gt; 0 &amp;&amp; warmLeads ||

                                            (x.LastHeatValue - SqlFunctions.DateDiff("week", !x.LastContactDate.HasValue
                                                                      ? x.InitialContactDate
                                                                      : x.LastContactDate.Value, DateTime.Today) *
                                            x.LeadPool.DecreaseLeadBy) &lt;= 0 &amp;&amp; !warmLeads
                                        )
                                   );


            predicate = predicate.Or(x =&gt; x.LeadPool.DecreaseByUnit == (int)DecreaseUnitTime.Month
                                       &amp;&amp;
                                       (
                                           (x.LastHeatValue - SqlFunctions.DateDiff("month", !x.LastContactDate.HasValue
                                                                      ? x.InitialContactDate
                                                                      : x.LastContactDate.Value, DateTime.Today) * x.LeadPool.DecreaseLeadBy) &gt; 0 &amp;&amp; warmLeads ||

                                            (x.LastHeatValue - SqlFunctions.DateDiff("month", !x.LastContactDate.HasValue
                                                                      ? x.InitialContactDate
                                                                      : x.LastContactDate.Value, DateTime.Today) *
                                            x.LeadPool.DecreaseLeadBy) &lt;= 0 &amp;&amp; !warmLeads
                                        )
                                   );


            var query = _activeLeads(ownerUserId)            
                        .AsExpandable().Where(predicate);

            return query;
        }


Any ideas on how to improve this?
First of all.  Is _queryLeadsByHeat supposed to represent a method?  If so I would steer away from using underscore in it's method name unless that's your naming convention in which case I guess your stuck with it.  Underscore is traditionally mainly reserved for fields (if at all as there are large debates for this practice).

I don't have Visual studio in front of me so not sure if this will even compile (or is even possible) but my initial thought would be to try and consolidate the Predicates into one method.

Expression&lt;Func&lt;T, bool&gt;&gt; GetHeatCondition(DecreaseUnitTime period)
{
    string periodAsString = period.ToString();

    return predicate.Or(x =&gt; x.LeadPool.DecreaseByUnit == (int)period
                               &amp;&amp;
                               (
                                   (x.LastHeatValue - SqlFunctions.DateDiff(periodAsString, !x.LastContactDate.HasValue
                                                              ? x.InitialContactDate
                                                              : x.LastContactDate.Value, DateTime.Today) * x.LeadPool.DecreaseLeadBy) &gt; 0 &amp;&amp; warmLeads ||

                                    (x.LastHeatValue - SqlFunctions.DateDiff(periodAsString, !x.LastContactDate.HasValue
                                                              ? x.InitialContactDate
                                                              : x.LastContactDate.Value, DateTime.Today) *
                                    x.LeadPool.DecreaseLeadBy) &lt;= 0 &amp;&amp; !warmLeads
                                )
                           );
}

private IQueryable&lt;Lead&gt; QueryLeadsByHeat(int? ownerUserId, bool warmLeads)
{
    var predicate = PredicateBuilder.False&lt;Lead&gt;();
    predicate = predicate.Or(GetHeatCondition&lt;Lead&gt;(DecreaseUnitTime.Day));
    predicate = predicate.Or(GetHeatCondition&lt;Lead&gt;(DecreaseUnitTime.Month));
    predicate = predicate.Or(GetHeatCondition&lt;Lead&gt;(DecreaseUnitTime.Year));

    var query = _activeLeads(ownerUserId)            
                        .AsExpandable().Where(predicate);

            return query;
}


I'm pretty sure that Linq query could be better optimized.  Have to think some more on that one...