它是Language Integrated Query。
當我們要對數據庫表進行查詢的時候,我們一定會編寫"select * from sometable where ID = .."的語句。好,那我們現在根據LINQ的語法,完全可以將我們熟悉的SQL中像"select","from","where"等語句在.NET Framework環境中順利使用并且大大提高開發的效率。
凡是有該標志的文章,都是該blog博主Caoer(草兒)原創,凡是索引、收藏
、轉載請注明來處和原文作者。非常感謝。
當我們要對數據庫表進行查詢的時候,我們一定會編寫"select * from sometable where ID = .."的語句。好,那我們現在根據LINQ的語法,完全可以將我們熟悉的SQL中像"select","from","where"等語句在.NET Framework環境中順利使用并且大大提高開發的效率。
下面我就牛刀小試,做個demo看看。
1. 先下載LinQ框架?
????現在最新版本是2006年5月發布"Orcas CTP", 下載地址(這里 )
2. 下載安裝待完畢。
3. 新建一個"LINQ Console Application"項目。
4. 輸入代碼如下:???
?1
?2
using?System;
?3
using?System.Collections.Generic;
?4
using?System.Text;
?5
using?System.Query;
?6
using?System.Xml.XLinq;
?7
using?System.Data.DLinq;
?8
?9
namespace?LINQConsoleApplication1
10

{
11
????class?Program
12
????
{
13
????????static?void?Main(string[]?args)
14
????????
{
15
????????????string[]?aBunchOfWords?=?
{"One","Two",?"Hello",?"World",?
16
17
"Four",?"Five"};
18
????????????var?result?=?
19
????????????from?s?in?aBunchOfWords?//?query?the?string?array?
20
????????????where?s.Length?==?5?????//?for?all?words?with?length?=?5
21
????????????select?s;???????????????//?and?return?the?string
22
????????????foreach?(var?s?in?result)?
{
23
????????????????Console.WriteLine(s);?//print
24
????????????}
25
????????}
26
????}
27
}
28
29

?2

?3

?4

?5

?6

?7

?8

?9

10



11

12



13

14



15



16

17

18

19

20

21

22



23

24

25

26

27

28

29

運行結果如下:
Hello
World
print any key to continue ...
凡是有該標志的文章,都是該blog博主Caoer(草兒)原創,凡是索引、收藏
、轉載請注明來處和原文作者。非常感謝。