LINQ
转:
http://www.cnblogs.com/Ring1981/archive/2007/01/08/421795.html
LINQ是什么?
它是Language Integrated Query。
当我们要对数据库表进行查询的时候,我们一定会编写 "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. 输入代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;
namespace LINQConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] aBunchOfWords = {"One","Two", "Hello", "World", "Four", "Five"};
var result = from s in aBunchOfWords // query the string array
where s.Length == 5 // for all words with length = 5
select s; // and return the string
foreach (var s in result)
{
Console.WriteLine(s); //print
}
}
}
}
运行结果如下:
Hello
World
print any key to continue ...
参考更多资料:
http://blog.csdn.net/programmer_editor/archive/2006/09/29/1305859.aspx
http://www.cnblogs.com/126/archive/2006/08/14/476800.html
http://www.cnblogs.com/Ring1981/archive/2007/01/08/421795.html
LINQ是什么?
它是Language Integrated Query。
当我们要对数据库表进行查询的时候,我们一定会编写 "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. 输入代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;
namespace LINQConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] aBunchOfWords = {"One","Two", "Hello", "World", "Four", "Five"};
var result = from s in aBunchOfWords // query the string array
where s.Length == 5 // for all words with length = 5
select s; // and return the string
foreach (var s in result)
{
Console.WriteLine(s); //print
}
}
}
}
运行结果如下:
Hello
World
print any key to continue ...
参考更多资料:
http://blog.csdn.net/programmer_editor/archive/2006/09/29/1305859.aspx
http://www.cnblogs.com/126/archive/2006/08/14/476800.html
浙公网安备 33010602011771号