I compared two queries that extract some pretty big data from a database table. For the query, I used Linq To Sql, and for the other, I use Passthrough SQL through ADO.NET.
I know that Linq To Sql should do a lot of work behind the scenes, but what does it actually do? Two queries retrieve the same amount of data, but the Linq To Sql query is more than 5 seconds slower and uses 150 MB of additional memory!
Here is my test code:
Using Linq To Sql:
public void MakeList() { int start = Environment.TickCount; var document = from d in _dm.tDokuments select d; List<tDokument> documentList = document.ToList(); int end = Environment.TickCount; GridView1.DataSource = documentList; GridView1.DataBind(); Label1.Text = (end - start).ToString(); }
Passthrough SQL + ADO.NET:
public void MakeList() { int start = Environment.TickCount; SqlCommand sqlCommand = new SqlCommand("SELECT * FROM tDokument", _connection); SqlDataAdapter da = new SqlDataAdapter(sqlCommand); DataSet ds = new DataSet(); da.Fill(ds); int end = Environment.TickCount; GridView1.DataSource = ds; GridView1.DataBind(); Label1.Text = (end - start).ToString(); }
sql data-binding linq-to-sql
Poku
source share