偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Linq City集合描述

開發(fā) 后端
這里介紹Linq City集合,包括介紹當(dāng)你寫LINQ查詢的時候你將在VS或免費的Visual Web Developer中獲得智能感知的提示。

稍微重構(gòu)一下Linq City集合

因為我們將在好幾個示例中重用這個Linq City集合,我決定把它封裝到一個"TravelOrganizer"類中,如下所示:

  1. using System;  
  2. using System.Collections.Generic;   
  3. public class TravelOrganizer  
  4. {  
  5. public List<Location> PlacesVisited  
  6. {  
  7. get  
  8. {  
  9. List<Location> cities = new List<Location>{  
  10. & nbsp; & nbsp;new Location { City="London"Distance=4789Country="UK" },  
  11. & nbsp; & nbsp;new Location { City="Amsterdam"Distance=4869Country="Netherlands" },  
  12. & nbsp; & nbsp;new Location { City="San Francisco"Distance=684Country="USA" },  
  13. & nbsp; & nbsp;new Location { City="Las Vegas"Distance=872Country="USA" },  
  14. & nbsp; & nbsp;new Location { City="Boston"Distance=2488Country="USA" },  
  15. & nbsp; & nbsp;new Location { City="Raleigh"Distance=2363Country="USA" },  
  16. & nbsp; & nbsp;new Location { City="Chicago"Distance=1733Country="USA" },  
  17. & nbsp; & nbsp;new Location { City="Charleston"Distance=2421Country="USA" },  
  18. & nbsp; & nbsp;new Location { City="Helsinki"Distance=4771Country="Finland" },  
  19. & nbsp;new Location { City="Nice"Distance=5428Country="France" },  
  20. & nbsp; & nbsp;new Location { City="Dublin"Distance=4527Country="Ireland" }  
  21. & nbsp; & nbsp;};  
  22.    
  23. return cities;  
  24. }  
  25. }  

這使我只需要編寫如下的代碼就能得到跟上面同樣的結(jié)果:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Web;  
  4. using System.Web.UI;  
  5. using System.Query;  
  6.    
  7. public partial class Step3 : System.Web.UI.Page  
  8. {  
  9. protected void Page_Load(object sender, EventArgs e)  
  10. {  
  11. TravelOrganizer travel = new TravelOrganizer();  
  12.    
  13. GridView1.DataSource = from location in travel.PlacesVisited  
  14. & nbsp; where location.Distance > 1000  
  15. & nbsp; orderby location.Country, location.City  
  16. & nbsp; select location;  
  17.    
  18. GridView1.DataBind();  
  19. }  

LINQ很酷之處就是它是強類型的。這意味著:

1) 你的所有的查詢都會進行編譯時檢查。不像現(xiàn)在的SQL語句,你只有到運行時才會發(fā)現(xiàn)你的錯誤所 在。這意味著你在開發(fā)時就可以檢查你的代碼的正確性,例如,如果我把上面的"distance"誤寫成 了"distanse",編譯器將為我捕獲到這個錯誤。

2) 當(dāng)你寫LINQ查詢的時候你將在VS或免費的Visual Web Developer中獲得智能感知的提示。這不僅加 快了編碼的輸入速度,而且使我們在處理無論簡單還是復(fù)雜的集合和數(shù)據(jù)源對象模型時都變得非常容易。以上介紹Linq City集合

【編輯推薦】

  1. LINQ to SQL Table淺談
  2. Linq語句問題的解決方法
  3. Ling to sql更新實體概述
  4. Linq實體繼承簡單描述
  5. Linq Library概述
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-09-09 15:37:27

Linq DataLo

2009-09-10 10:37:15

LINQ to SQL

2009-09-16 09:38:27

LINQ To SQL

2009-09-14 15:43:12

Linq Settin

2009-09-09 15:28:43

Linq to obj

2009-09-14 10:57:46

LINQ入門

2009-09-18 16:00:07

LINQ架構(gòu)

2009-09-15 16:26:36

Linq orderb

2009-09-08 09:24:50

LINQ查詢

2009-09-15 11:14:33

LINQ to SQL

2009-09-17 09:24:57

Linq實現(xiàn)分頁

2009-09-11 10:20:36

Linq擴展方法

2009-09-14 16:33:55

LINQ To XML

2009-09-14 10:20:52

LINQ查詢語法

2009-09-09 11:14:04

Linq多個結(jié)果集

2009-09-10 09:09:40

Linq實體繼承

2009-09-16 10:58:13

Linq數(shù)據(jù)分組

2009-09-16 15:48:05

Linq修改XML文檔

2009-09-17 17:14:54

linq to sql

2009-09-18 13:53:09

LINQ工具集
點贊
收藏

51CTO技術(shù)棧公眾號