02 {
03 public static IQueryable<T> Where<T>(
04 this IQueryable<T> source, Expression<Func<T, bool>> predicate)
05 {
06 Console.WriteLine("Calling Where in the customer extension method");
07
08 return Queryable.Where(source, predicate);
09 }
10 }
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 var context = GenerateContext();
16 var result =
17 from c in context.Customers
18 where c.City == "London"
19 select c;
20
21 Console.WriteLine(result.Count());
22 }
23 }
24 // 输出:
25 Calling Where in the customer extension method
26 6
总结:本节讨论了Expression Tree/Expression/Lambda Expression/Query expression/Query Operator的含义和区别,示例了如何构建Expression Tree,正确使用lambda expression,以及如何通过extension method来扩展query expression。