Let’s look over the following code:
The cause of this problem is not from the order function. This is a core function of .NET that works perfect.
The ordering is not made on the both blocks of the IF. Because in general the list were already ordered in database and the clients usually didn’t reach the ELSE block of the code, these case appear very rarely.
public List<Result> SomeFunction(string machineId)
{
  ...
  if(machineId == null)
  {
    ...
    List<Result> results = GetAllResults();
    return results.OrderByDescending(x => x.Date);
  }
  else 
  {  
    ...
    return GetResultsByMachine(machineId);  
  }
}
The cause of this problem is not from the order function. This is a core function of .NET that works perfect.
The ordering is not made on the both blocks of the IF. Because in general the list were already ordered in database and the clients usually didn’t reach the ELSE block of the code, these case appear very rarely.
public List<Result> SomeFunction(string machineId)
{
  ...
  List<Result> results
  if(machineId == null)
  {
    ...
    results = GetAllResults();
  }
  else 
  {  
    ...
    results = GetResultsByMachine(machineId);  
  }
  return results.OrderByDescending(x => x.Date);
}
Comments
Post a Comment