• [织梦吧]唯一域名:www.dedecms8.com,织梦DedeCMS学习平台.

当前位置: > 编程与数据库 > net编程 >

LINQ那些事儿(4)- Query Expression和Query Operator(4)

来源: www.dedecms8.com 编辑:织梦吧 时间:2012-06-27点击:

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。

About D8

  • ©2014 织梦吧(d8) DedeCMS学习交流平台
  • 唯一网址 www.DedeCMS8.com 网站地图
  • 联系我们 1978130638@qq.com ,  QQ