Asp.Net provides a number of Data Access Technologies,
like ADO.Net, LINQ-to-SQL, Entity Framework etc, each one of these technologies
has its own advantages and disadvantages, while designing an application; we
need to identify the appropriate data access technology to achieve maximum
efficiency.
Here we shall evaluate the data access performance of ADO.net
and LINQ-to-SQL in populating a DropDownList with 1000 list
items.
The configuration of the system used to perform the
evaluation is as follows.
OS
|
Windows XP
Professional 2002 SP3
|
Processor
|
Pentium® D 2.66 GHz
|
RAM
|
3 GB
|
The performance test was
carried out for 25 iterations with both ADO.net and LINQ-to-SQL, the results of
the test are as follows.
The test results clearly indicate that the conventional ADO.Net
technology has a distinct edge over LINQ-to-SQL, when it comes to Data Loading
operations.
However LINQ-to-SQL is not to be under estimated as it has its own
advantages, use the right technology at the right place.
The code used to perform the test is as follows
ADO.Net
SqlConnection objConn;
SqlCommand objCmd;
SqlDataAdapter objDA;
DataSet dsEmployee;
Stopwatch timer;
string strQuery = string.Empty;
timer = new Stopwatch();
timer.Start();
string strConn = ConfigurationManager.ConnectionStrings["EmployeesConnectionString"].ToString();
objConn = new SqlConnection(strConn);
strQuery = "SELECT
ID, Name FROM Employee";
objCmd = new SqlCommand(strQuery, objConn);
objDA = new SqlDataAdapter(objCmd);
dsEmployee = new DataSet();
objDA.Fill(dsEmployee, "dtEmployee");
drpEmployee.DataSource = dsEmployee.Tables["dtEmployee"];
drpEmployee.DataTextField = "Name";
drpEmployee.DataValueField = "ID";
drpEmployee.DataBind();
timer.Stop();
lblExecutionTime.Text = "Execution
Time (Milliseconds):" + timer.ElapsedMilliseconds.ToString();
LINQ to SQL
Stopwatch timer;
EmployeeClassesDataContext dbContext = new EmployeeClassesDataContext();
timer = new Stopwatch();
timer.Start();
var emp = (from e in dbContext.Employees select
new { e.ID, e.Name});
drpEmployee.DataSource = emp;
drpEmployee.DataTextField = "Name";
drpEmployee.DataValueField = "ID";
drpEmployee.DataBind();
timer.Stop();
lblExecutionTime.Text = "Execution
Time (Milliseconds):" + timer.ElapsedMilliseconds.ToString();
That’s it we have evaluated the performance of ADO.net
and LINQ-to-SQL in loading a DropDownList with 1000 items.
RELATED POST
No comments:
Post a Comment