Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

On my very first project on ASP Core I have come across a trouble that strangely has not to have been resolved yet although seems quite simple.

On a details page of an Accounts Model I seek to have the table reflecting balances (transactions) entries, pertaining to the relevant account, in a descending date order:

C#
public async Task<iactionresult> Details(string _SrcSys, string _CustId, string _AccId)
        {
            if (_SrcSys == null || _CustId == null || _AccId == null)
            {
                return NotFound(); // The three are Composite Key elements
            }

            var Accs = await _context.Accounts
                       .Include(Bal => Bal.Balances)
                       .OrderBy(Bal => Bal.Balances.OrderByDescending(x => x.RepDt)) //Why isn't this sorting the result?
                       .SingleOrDefaultAsync(x => x.SrcSys == _SrcSys && x.CustId == _CustId && x.AccId == _AccId);

            return View(Accs);

What could be the error? The portion in simple words is that why doesn't .OrderBy(Bal => Bal.Balances.OrderByDescending(x => x.RepDt)) help in having the balances table be sorted on the Accounts' Details Page?

Please help!

What I have tried:

The code in many shapes and question placed searched on google, but can't find any help.
Posted
Updated 21-May-17 20:43pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900