var query=(from w in widgets where w.Name.Contains("xyz") select w); var result = flag ? query.OrderBy(w =>w) : query.OrderByDescending(w = w);