接触LINQ

昨天刚上班第一天装了半天的软件,今天稍微用了下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,虽然提高了维护性,但貌似这样的开发效率明显降低不少,还是先写到这吧,继续研究下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值