/// <summary> /// A simple example of how to combine expressions (i.e., how to have one expression call another). /// </summary> static void TestExpressionCombiner() { var criteria1 = Linq.Predicate <Purchase>(p => p.Price > 1000); var criteria2 = Linq.Predicate <Purchase>(p => criteria1.Invoke(p) || p.Description.Contains("a")); //Expression<Func<Purchase, bool>> criteria1 = p => p.Price > 1000; //Expression<Func<Purchase, bool>> criteria2 = p => criteria1.Invoke(p) || p.Description.Contains("a"); Console.WriteLine("Here's what criteria2 looks like, before calling Expand"); Console.WriteLine(criteria2.ToString()); Console.WriteLine(); Console.WriteLine("Here's what criteria2 looks like, after calling Expand"); Console.WriteLine(criteria2.Expand().ToString()); var data = new DemoData(); // We can use criteria2 in either of two ways: either call Expand on the expression before using it: var query = data.Purchases.Where(criteria2.Expand()); Console.WriteLine("Count: " + query.Count()); // or call AsExpandable() on the Table: query = data.Purchases.AsExpandable().Where(criteria2); Console.WriteLine("Count: " + query.Count()); }