Oh, maybe it has to do with the paging? LoadForCategory determines which records to return based on the page size and page index, but it is ordering things using the Product OrderBy field, then counting where to start and how many to return in that order. I should have thought of that earlier, sorry.
I guess the next step is to analyze the following using the debugger or creating error log entries:
Code: Select all
IList<Product> visibleNodes = ProductDataSource.LoadForCategory(true, this.CategoryId, false, true, SortResults.SelectedValue, _pageSize, (_HiddenPageIndex * _pageSize));
// A. what is the order of the IDs in visibleNodes here?
IList<int> catalogNodeOrder = NHibernateHelper
.CreateSQLQuery("select CatalogNodeId from ac_CatalogNodes where CategoryID = " + this.CategoryId + " order by OrderBy")
.List<int>();
// B. what is the order of the IDs in catalogNodeOrder here?
visibleNodes = visibleNodes.OrderBy(vn => catalogNodeOrder.IndexOf(vn.Id)).ToList();
// C. what is the order of the IDs in visibleNodes here?
D. what is the order of the IDs on the rendered page (by looking up the IDs of the product names)
If the answer is not as expected at B, not sure what the problem is, that is just a simple query with an order clause, so it should give the same as running it in Mgmt Studio.
If the answer is not as expected at C, maybe the .OrderBy(...IndexOf...) trick doesn't work. Seems like it should though.
if the answer is not as expected at D, then maybe it has to do with the paging, or some other code is changing the order after C but before the results are rendered.