Order By It does not return the last MVC value

1

MVC - Why does not this code return the last value, but returns the largest value?

 int LastRegister = db.suma1.OrderByDescending(x => x.suma).First().suma;
    
asked by Jesus Reyes Trujillo 13.08.2018 в 21:00
source

1 answer

1

Because you are sorting in descending order on all your sums, not among the records.

You can call it by the id or your accountant

int LastRegister = db.suma1.OrderByDescending(x => x.id).First().suma;

Or use the function of the last one exactly

int LastRegister = db.suma1.LastorDefault().suma;
    
answered by 13.08.2018 в 21:08