1

我正在使用查詢從名爲customers的表中獲取記錄,並且我想通過address, housenumber, surname, name訂購記錄。提高查詢性能,以便通過Linq-to-SQL訂購記錄

首先,我現在用這個(數據表)

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

我用這個:

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(...);  
} 

這是正確的方式來提高性能...?

OrderedEnumerableRowCollection vs DataTable的(dis)優點是什麼?

請讓我知道你應該如何做到這一點。

回答

0

我會說這取決於您的SQL Server的索引,哪個更快。例如,如果SQL Server被索引以便它可以快速執行排序(或者數據非常小),那麼數據表就沒有問題。

我通常會期望SQL服務器比.NET代碼更高效。

雖然在一般的建築注意事項。如果排序是一個UI關注的問題(從你的問題來看它不是很清楚),那麼排序的客戶端更有意義,特別是如果你要在別處使用數據表(可能以不同的順序)。

+0

我認爲訂購效率不如數據庫,因爲硬盤比機器內存慢? – Ruutert

+0

我有一個類別與子類別和子類別有訂單。類別有排序代碼和描述也有序。分類存儲在分類表和orderlines在訂單項目表 00 A組 00 SUB A組 00-000訂單行1 等 我想在這裏建立從一棵樹,這怎麼辦?通過SQL或Linq? – Ruutert