LINQ查询结果分析

开发 后端
这里介绍LINQ查询结果,如果查询结果是强类型的,如string[],List<T>等,就可以不用var类型,而是使用合适的 IEnumerable<T>或IEnumerable(因为IEnumerable<T>也扩展了IEnumerable)类型。

本文向大家介绍LINQ查询结果,可能好多人还不了解LINQ查询结果,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。

使用LINQ查询结果

如果查询结果是强类型的,如string[],List<T>等,就可以不用var类型,而是使用合适的 IEnumerable<T>或IEnumerable(因为IEnumerable<T>也扩展了IEnumerable)类型。

  1. class Program  
  2. {  
  3. static void Main(string[] args)  
  4. {  
  5. Console.WriteLine("***** LINQ Transformations *****"n");  
  6. IEnumerable<string> subset = GetStringSubset();  
  7. foreach (string item in subset)  
  8. {  
  9. Console.WriteLine(item);  
  10. }  
  11. Console.ReadLine();  
  12. }  
  13. static IEnumerable<string> GetStringSubset()  
  14. {  
  15. string[] currentVideoGames = {"Morrowind", "BioShock",  
  16. "Half Life 2: Episode 1", "The Darkness",  
  17. "Daxter", "System Shock 2"};  
  18. // Note subset is an IEnumerable<string> compatible object.  
  19. IEnumerable<string> subset = from g in currentVideoGames  
  20. where g.Length > 6  
  21. orderby g  
  22. select g;  
  23. return subset;  
  24. }  

使用LINQ查询结果的分页处理:

  1. var custTotalOrders = from c in db.D_WorkCenter  
  2. //join o in db.Orders  
  3. //on c.CustomerID equals o.CustomerID into custOrders  
  4. //from o in custOrders  
  5. select new  
  6. {  
  7. WorkCenterID = c.WorkCenterID,  
  8. WorkCenterName = c.WorkCenterName  
  9. //OrderTotal = o.Order_Details.Sum(d => d.UnitPrice * d.Quantity)  

【编辑推荐】

  1. Linq to SQL学习经验
  2. Linq隐式类型化局部变量
  3. Linq匿名类型简单概述
  4. Linq Lambda表达式剖析
  5. Linq对象初始值浅谈
责任编辑:佚名 来源: IT168
相关推荐

2009-09-17 08:47:00

Linq查询

2009-09-15 10:46:04

LINQ to SQL

2009-09-16 15:41:45

LINQ查询XML文档

2009-09-18 16:46:15

LINQ查询句法

2009-09-14 18:53:27

LINQ查询

2009-09-16 10:48:32

LINQ查询操作

2009-09-15 14:58:26

Linq查询本质

2009-09-15 15:45:00

Linq联合查询

2009-09-14 17:03:32

LINQ模糊查询

2009-09-17 17:03:13

LINQ动态查询

2023-10-27 11:15:18

内存query打印

2009-09-09 10:58:58

Linq结果集形状

2009-09-09 11:14:04

Linq多个结果集

2009-09-16 10:08:06

LINQ查询

2009-09-16 10:38:43

LINQ查询

2009-09-17 13:15:20

LINQ查询

2009-09-14 10:13:02

LINQ查询操作

2009-09-09 16:53:53

LINQ查询语法

2009-09-08 17:27:18

LINQ to Dat

2009-09-10 16:28:17

LINQ查询
点赞
收藏

51CTO技术栈公众号