none
LINQ To DataSet : asking about performance RRS feed

  • Question

  • Hello ,

      look at this sample plz :

      

    SqlDataAdapter dataAdapter = new SqlDataAdapter(
    @"SELECT O.EmployeeID, E.FirstName + ' ' + E.LastName as EmployeeName,
    O.CustomerID, C.CompanyName, O.ShipCountry
    FROM Orders O
    JOIN Employees E on O.EmployeeID = E.EmployeeID
    JOIN Customers C on O.CustomerID = C.CustomerID"
    ,connectionString);

    DataSet dataSet = new DataSet();
    dataAdapter.Fill(dataSet,
    "EmpCustShip");

    // Quesry 1
    var ordersQuery = dataSet.Tables["EmpCustShip"].AsEnumerable()
                             .Where(r => r.Field<
    string>("ShipCountry").Equals("Germany"))
                             .Distinct(System.Data.
    DataRowComparer.Default)
                             .OrderBy(r => r.Field<
    string>("EmployeeName"))
                             .ThenBy(r => r.Field<
    string>("CompanyName"));


    // Quesry 2
    var ordersQuery = (from r in dataSet.Tables["EmpCustShip"].AsEnumerable()
                              
    where r.Field<string>("ShipCountry").Equals("Germany")
                               
    orderby r.Field<string>("EmployeeName"),
                               r.Field<
    string>("CompanyName")
                               
    select r).Distinct(System.Data.DataRowComparer.Default);

     

    Could I know which one  of them is a good Performance (Quesry 1  or Quesry 2 ) ?? and Why ?


     Thanks





    ASk
    Monday, January 19, 2009 10:47 AM

Answers

  • The primary difference being at what point in time the set of rows reduced to the distinct set.
    In both cases all rows will evaluated for distinctness.

    With that in mind, and not actually testing - I estimate the first query would be faster because can reduce the number of DataRow that need to be actually sorted.

    If you want to test - try both with when you have an initial dataset that is already unique vs. a dataset that has many duplicates.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to mark the replies as answers if they help.
    Tuesday, January 20, 2009 1:22 AM
    Moderator