Hello,
I have compared two queries which fetch some fairly large data from a database table. For query one I used Linq To Sql and for the other I use passthrough SQL via ADO.NET.
I know that Linq To Sql has to do a lot of work behind the scenes, but what is it actually doing? The two queries fetches the same amount of data but the Linq To Sql query is more than 5 seconds slower and uses 150mb more RAM!
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();
}