Linq To Sql 与ADO.NET

简单测试

1:使用DataContacxt 捞取Customers数据

            int iStar = System.Environment.TickCount;
            DataContext dc = new DataContext("Server = .;uid=sa;pwd=p7zx5dez;database=Northwind");
            Table<Customer> _Table = dc.GetTable<Customer>();
            this.dataGridView1.DataSource = from c in _Table  select new { 客户编号 = c.CustomerID, 客户名称 = c.Name, 客户城市 = c.City };
            int iEnd = System.Environment.TickCount;
            this.txtUseTime.Text = ("Star:" + iStar.ToString() + " End:" + iEnd.ToString() + " Use Time:" + (iEnd - iStar).ToString() + " 毫秒");

2:使用ADO捞取数据量一样的数据

            int iStar = System.Environment.TickCount;
            using (SqlConnection Conn = new SqlConnection("Server = .;uid=sa;pwd=p7zx5dez;database=NorthWind"))
            {
                DataTable _Table = new DataTable();
                using (SqlDataAdapter Adapter = new SqlDataAdapter("Select * from Customers", Conn))
                {
                    Adapter.Fill(_Table);
                    this.dataGridView1.DataSource = _Table;
                }
            }
            int iEnd = System.Environment.TickCount;
            this.txtUseTime.Text = ("Star:" + iStar.ToString() + " End:" + iEnd.ToString() + " Use Time:" + (iEnd - iStar).ToString() + " 毫秒");

 

总结:第一次捞取DataContaxt使用的时间相对会比ADO慢

      多次测试,发现DataContaxt捞取耗时没有变化,ADO则会编号

     说明DataContaxt是有缓存功能的

转载于:https://www.cnblogs.com/zyzhang/archive/2011/04/06/2006722.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值