在MVC3中按升序记录数字

时间:2011-05-19 13:01:09

标签: asp.net-mvc-3 entity-framework-4

我有以下查询:

  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); 

我是否可以按升序排列显示记录编号,同时保持记录的降序。

请建议。

由于

1 个答案:

答案 0 :(得分:1)

尝试使用RecordNumber上的OrderBy,然后StateChangeDate上的ThenByDescending

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