private Expression <Func <Note, bool> > GetFilterExpression(Guid?ownerId, string title, string text, string[] tags) { Expression <Func <Note, bool> > exp = null; if (ownerId != null) { exp = e => e.CreatedBy == ownerId; } if (title != null) { exp = QueryableExtensions.AndAlso(exp, e => e.Title.Contains(title)); } if (text != null) { exp = QueryableExtensions.AndAlso(exp, e => e.Text.Contains(text)); } if (tags != null && tags.Any()) { Expression <Func <Note, bool> > expTags = null; foreach (var tag in tags) { expTags = expTags == null ? e => e.Tags.Any(t => t.Value == tag) : QueryableExtensions.CombineOr(expTags, e => e.Tags.Any(t => t.Value == tag)); } exp = QueryableExtensions.AndAlso(exp, expTags); } return(exp); }