I have a simple if statement which, based on user input, determines which expression is going to be utilized. It looks like it can be done better.Func<Unit, bool> exp;if (onlyChildren)    exp = u => u.PhaseId == id;else    exp = u => u.PhaseId != id;var unitGroups = _db.Units.Where(exp).GroupBy(m => m.UnitTemplate, (m, group) => new UnitTemplateZoneVm(){    Id = m.Id,    Units = group.ToList()}).ToList();
Filtering units by a dynamic Lambda expression
c#;linq;lambda
First of all, I support @EBrown about whitespace and braces. Some other ideas depending on what you are doing:Use the conditional if, so you can logically see the if-else. Put logic into a method when you're using the same filter multiple timesExample:....Where(u => (onlyChildren ? ChildFilter(u,id) : !ChildFilter(u,id))   ...public static bool ChildFilter(Unit unit, int id){    return unit.PhaseId == id;}In case the boolean value is not due to user input, but from different classes. You could consider:passing the func as a parameter, [optional] using enum object patternpassing the caller as a parameter which implements an interface with a filtering methodClean code VS. Overkill