接触LINQ
http://www.diybl.com/ 2008-3-4 网络 点击:
[ 评论 ]
文章搜索:
【点击打包该文章】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Text;

namespace mycmdLinq

...{
class Program

...{
static void Main(string[] args)

...{
//DataContext db = new DataContext(@"APK-8020CCPNorthwind");
DataContext db = new DataContext(@"server=APK-8020CCP;database=Northwind;uid=sa;pwd=123");
Table<Customer> Customers = db.GetTable<Customer>();
db.Log = Console.Out;
IQueryable<Customer> custQuery =
from cust in Customers
where cust.City == "London"
select cust;
foreach (Customer cust in custQuery)

...{
Console.WriteLine("ID={0},City={1}",cust.CustomerID,cust.City);
}

Console.ReadLine();
}
}

[Table(Name = "Customers")]
public class Customer

...{
private string m_CustomerID;
[Column(IsPrimaryKey = true, Storage = "m_CustomerID")]
public string CustomerID

...{

get ...{ return m_CustomerID; }

set ...{ m_CustomerID = value; }
}

private string m_City;
[Column(Storage = "m_City")]
public string City

...{

get ...{ return m_City; }

set ...{ m_City = value; }
}


}
}
有用到对象模型,就是之前经常用到的MODEL,虽然提高了维护性,但貌似这样的开发效率明显降低不少,还是先写到这吧,继续研究下
昨天刚上班第一天装了半天的软件,今天稍微用了下VS08,研究了下LINQ TO SQL,参照MSDN的教程,在数据库连接上还是花费了不少时间,主要是2000和05共存,如果DataContext指定的是数据库文件,会自动附加上05的数据库上,这里又暂时没安装SQL SERVER 05的客户端。。所以还是得手动指定。。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Text;
namespace mycmdLinq
...{
class Program
...{
static void Main(string[] args)
...{
//DataContext db = new DataContext(@"APK-8020CCPNorthwind");
DataContext db = new DataContext(@"server=APK-8020CCP;database=Northwind;uid=sa;pwd=123");
Table<Customer> Customers = db.GetTable<Customer>();
db.Log = Console.Out;
IQueryable<Customer> custQuery =
from cust in Customers
where cust.City == "London"
select cust;
foreach (Customer cust in custQuery)
...{
Console.WriteLine("ID={0},City={1}",cust.CustomerID,cust.City);
}
Console.ReadLine();
}
}
[Table(Name = "Customers")]
public class Customer
...{
private string m_CustomerID;
[Column(IsPrimaryKey = true, Storage = "m_CustomerID")]
public string CustomerID
...{
get ...{ return m_CustomerID; }
set ...{ m_CustomerID = value; }
}
private string m_City;
[Column(Storage = "m_City")]
public string City
...{
get ...{ return m_City; }
set ...{ m_City = value; }
}

}
}
有用到对象模型,就是之前经常用到的MODEL,虽然提高了维护性,但貌似这样的开发效率明显降低不少,还是先写到这吧,继续研究下如果图片或页面不能正常显示请点击这里 站内搜索:
推荐文章 |
