1

I'm using a query to get records from a table named customers and I want to order the records by address, housenumber, surname, name.

First I used this (DataTable)

public CustomerInfo.customers GetCustomers(string zipcode) {
     string sql = "select id, name, surname, zipcode, housenumber where zipcode = @_zipcode order by address, housenumber, surname, name";
 ....     
}

now I use this:

public OrderedEnumerableRowCollection<CustomerInfo.customerRow> GetCustomers(string zipcode) {
     string sql = "select id, name, surname, zipcode, housenumber where zipcode = @_zipcode";

     ....

     return (from c in datatable).OrderBy(c => c.Address).ThenBy(....).ThenBy(...);       
}

Is that the right way to improve performance ...?

What are the (dis)advantages of the OrderedEnumerableRowCollection vs DataTable?

Please let me know how you should do this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ruutert
  • 395
  • 1
  • 7
  • 18

1 Answers1

0

I would say it depends on the indexing at your SQL Server as to which is faster. For instance if the SQL Server is indexed such that it can do the ordering quickly (or the data is very small) then the data table is fine.

I would generally expect the SQL server to be more efficient at this than the .NET code.

On a general architectual note though. If the ordering is a UI concern (it's not clear from your question if it is) then the ordering client-side makes more sense, especially if you'll use the datatable elsewhere (potentially in a different order).

Joel Mansford
  • 1,306
  • 7
  • 13
  • I thought ordering is less efficient to do by a DB because the Harddisk is slower than machine memory?? – Ruutert Oct 06 '12 at 11:15
  • I have a category with subcategories and subcategories have orderlines. categories have sorting codes and description also orderlines. Categories are stored in Category table and orderlines in orderline table 00 GROUP A 00 SUB GROUP A 00-000 OrderLine 1 etc I want to build a tree here from, How to do this ?? by SQL or Linq? – Ruutert Oct 06 '12 at 11:21