Linq To Sql 与ADO.NET
时间:2011-04-06 来源:沉默的人
简单测试
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是有缓存功能的