We have an error log table with columns like MachineName, EventSource, ErrorMessage, EventDate. UI has dynamic list of checkboxes for machines and events. We needed a way to build a query against EF context which conceptually be something like

SELECT *  
FROM ErrorLogs  
WHERE MachineName = 'Server1' OR MachineName = 'Server2'  

Values of OR constants are driven by user's selecting checkboxes and known at run time.

With the help of great MSDN article this turned out in simplified form to:

public IList<ErrorLog> GetErrorLog(IList<string> eventSources, IList<string> machines)  
{
    IQueryable<ErrorLog> query = _context.ErrorLog.AsQueryable();

    if (eventSources != null)
    {
        query = QueryBuilder.AppendConstantsWithOr<ErrorLog>(query, "EventSource", eventSources);
    }

    if (machines != null)
    {
        query = QueryBuilder.AppendConstantsWithOr<ErrorLog>(query, "MachineName", machines);
    }            

    return query.ToList();            
}

Here is QueryBuilder helper class that is used above:

public class QueryBuilder  
{
    /// <summary>
    /// Appends where clause for the given list of constants, for example Where(s => s.ApplicationSource == "a" || s.ApplicationSource == "b")
    /// </summary>
    /// <typeparam name="T">Type run query against, for example ErrorLog</typeparam>
    /// <param name="query">Current where clause, must not be null</param>
    /// <param name="propertyName">Name of the property in the given type, "ApplicationSource" in this example</param>
    /// <param name="constants">List of constants, in this example "a", "b"</param>
    /// <returns>Modified where clause</returns>
    public static IQueryable<T> AppendConstantsWithOr<T>(IQueryable<T> query, string propertyName, IList<string> constants)
    {
        if (query == null)
        {
            throw new ArgumentException("Must have initial query", "query");
        }

        if (constants == null)
        {
            throw new ArgumentException("Must have list of constants", "constants");
        }

        ParameterExpression pe = Expression.Parameter(typeof(ErrorLog), "s");
        Expression left = Expression.Property(pe, typeof(ErrorLog).GetProperty(propertyName));
        Expression predicateBody = null;

        foreach (var src in constants)
        {
            Expression right = Expression.Constant(src);
            Expression e = Expression.Equal(left, right);
            if (predicateBody == null)
            {
                predicateBody = e;
            }
            else
            {
                predicateBody = Expression.OrElse(predicateBody, e);
            }
        }

        MethodCallExpression whereCallExpression = Expression.Call(
            typeof(Queryable),
            "Where",
            new Type[] { query.ElementType },
            query.Expression,
            Expression.Lambda<Func<T, bool>>(predicateBody, new ParameterExpression[] { pe }));

        return query.Provider.CreateQuery<T>(whereCallExpression);
    }
}