昨天刚上班第一天装了半天的软件,今天稍微用了下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; }
}
}
}
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; }
}
}
}