自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Linq City集合描述

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

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

因?yàn)槲覀儗⒃诤脦讉€(gè)示例中重用這個(gè)Linq City集合,我決定把它封裝到一個(gè)"TravelOrganizer"類(lèi)中,如下所示:

  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. }  

這使我只需要編寫(xiě)如下的代碼就能得到跟上面同樣的結(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很酷之處就是它是強(qiáng)類(lèi)型的。這意味著:

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

2) 當(dāng)你寫(xiě)LINQ查詢(xún)的時(shí)候你將在VS或免費(fèi)的Visual Web Developer中獲得智能感知的提示。這不僅加 快了編碼的輸入速度,而且使我們?cè)谔幚頍o(wú)論簡(jiǎn)單還是復(fù)雜的集合和數(shù)據(jù)源對(duì)象模型時(shí)都變得非常容易。以上介紹Linq City集合

【編輯推薦】

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

2009-09-09 15:37:27

Linq DataLo

2009-09-10 10:37:15

LINQ to SQL

2009-09-14 15:43:12

Linq Settin

2009-09-16 09:38:27

LINQ To SQL

2009-09-14 10:57:46

LINQ入門(mén)

2009-09-09 15:28:43

Linq to obj

2009-09-15 16:26:36

Linq orderb

2009-09-18 16:00:07

LINQ架構(gòu)

2009-09-15 11:14:33

LINQ to SQL

2009-09-11 10:20:36

Linq擴(kuò)展方法

2009-09-08 09:24:50

LINQ查詢(xún)

2009-09-14 10:20:52

LINQ查詢(xún)語(yǔ)法

2009-09-17 09:24:57

Linq實(shí)現(xiàn)分頁(yè)

2009-09-14 16:33:55

LINQ To XML

2009-09-17 17:14:54

linq to sql

2009-09-09 11:14:04

Linq多個(gè)結(jié)果集

2009-09-18 13:53:09

LINQ工具集

2009-09-10 09:09:40

Linq實(shí)體繼承

2009-09-16 10:58:13

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

2009-09-16 15:48:05

Linq修改XML文檔
點(diǎn)贊
收藏

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