2011-05-19 29 views
1

我有以下查詢:記錄號碼MVC3

var accounts = 
    from account in context.Accounts 
    from guranteer in account.Gurantors 

select new AccountsReport 
    { 
     CreditRegistryId = account.CreditRegistryId, 
     AccountNumber = account.AccountNo, 
     DateOpened = account.DateOpened, 
    }; 

return accounts.AsEnumerable() 
        .Select((account, index) => new AccountsReport() 
          { 
           RecordNumber = FormattedRowNumber(account, index + 1), 
           CreditRegistryId = account.CreditRegistryId, 
           AccountNumber = FormattedAccountNumber(account.AccountType, account.AccountNumber)}).OrderByDescending(c => c.StateChangeDate); 

It works fine except one problem and that is it returns records number in reverse order like 3, 2,1 because of .OrderByDescending(c => c.StateChangeDate); 

我可以在ascendeing爲了記錄數量,同時保持記錄按降序排列。

請建議。

感謝

回答

1

嘗試使用OrderByRecordNumber然後ThenByDescendingStateChangeDate

.OrderBy(c => c.RecordNumber).ThenByDescending(c => c.StateChangeDate);