详谈Linq查询结果分析的方法

开发 后端
很多人还不是很了解Linq查询结果,为了解决大家的这个盲区,笔者写了一篇关于内容的文章,当你看完本文一定会收获很大的。

很多人还不是很了解Linq查询结果,为了解决大家的这个盲区,笔者写了一篇关于内容的文章,当你看完本文一定会收获很大的。

使用Linq查询结果:

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

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

以上就是对Linq查询结果的简单分析。

【编辑推荐】

  1. 简单解决Linq多条件组合问题
  2. 将数据源进行Linq排序
  3. Ordering方法实现Linq排序
  4. 轻轻松松学习Linq排序
  5. 详解Linq联合查询表结果集的返回
责任编辑:阡陌 来源: 新客网
相关推荐

2009-09-14 10:09:26

LINQ查询结果

2009-09-14 18:53:27

LINQ查询

2009-09-15 10:46:04

LINQ to SQL

2009-09-17 17:03:13

LINQ动态查询

2009-09-15 15:45:00

Linq联合查询

2009-09-16 15:41:45

LINQ查询XML文档

2009-09-18 16:46:15

LINQ查询句法

2009-09-16 10:48:32

LINQ查询操作

2009-09-15 14:58:26

Linq查询本质

2023-10-27 11:15:18

内存query打印

2009-09-17 11:29:50

Linq扩展方法

2009-09-14 17:03:32

LINQ模糊查询

2009-09-13 21:52:16

LINQ字符串

2009-09-09 11:14:04

Linq多个结果集

2009-09-09 10:58:58

Linq结果集形状

2009-08-27 13:10:54

LINQ from子句

2009-09-14 18:41:59

LINQ查询

2009-09-15 10:35:11

linq多表查询

2009-09-16 10:08:06

LINQ查询

2009-09-17 13:15:20

LINQ查询
点赞
收藏

51CTO技术栈公众号