Linq To Sql 與ADO.NET
簡(jiǎn)單測(cè)試
1:使用DataContacxt 撈取Customers數(shù)據(jù)
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 { 客戶編號(hào) = 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撈取數(shù)據(jù)量一樣的數(shù)據(jù)
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() + " 毫秒");
總結(jié):第一次撈取DataContaxt使用的時(shí)間相對(duì)會(huì)比ADO慢
多次測(cè)試,發(fā)現(xiàn)DataContaxt撈取耗時(shí)沒有變化,ADO則會(huì)編號(hào)
說明DataContaxt是有緩存功能的
posted on 2011-04-06 13:39 沉默的人 閱讀(292) 評(píng)論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)