public static IEnumerable <T> Where <T>(this IndexedCollection <T> source, Expression <Func <T, bool> > query) { Contract.Requires(source != null); Contract.Requires(query != null); Contract.Ensures(Contract.Result <IEnumerable <T> >() != null); var concatenatedParts = new List <IEnumerable <T> >(); query = query.Reduce() as Expression <Func <T, bool> >; var parameter = query.Parameters.First(); Expression outRawExpression = null; Expression currentPart; for (currentPart = query.Body; currentPart.NodeType == ExpressionType.And || currentPart.NodeType == ExpressionType.AndAlso; currentPart = (currentPart as BinaryExpression).Right) { var activePart = (currentPart as BinaryExpression).Left; CheckForEqualExpression(source, concatenatedParts, activePart, ref outRawExpression, parameter); } if (currentPart.NodeType == ExpressionType.Equal) { CheckForEqualExpression(source, concatenatedParts, currentPart, ref outRawExpression, parameter); } if (!concatenatedParts.Any()) { return(source.AsEnumerable().Where(query.Compile())); } var aggregatedObjects = concatenatedParts.Aggregate((a, s) => a == null ? s : a.Where(s.Contains)); if (!aggregatedObjects.Any() || outRawExpression == null) { return(aggregatedObjects); } var outExpression = Expression.Lambda <Func <T, bool> >(outRawExpression, parameter); return(aggregatedObjects.Where(outExpression.Compile())); }