-1

I'm new on development and want to make a small change by adding orderby to the existing code. Can someone enlighten me on how to orderby to this piece of code?

    public List<Employee> GetAllEmployees()
    {
        ebll employeeBll = new EmployeeBLL();
        return ebll.GetAllEmployees();
    }
Skippy
  • 1

2 Answers2

0

Set reference to Linq before doing this. I used employee LastName for order by

public List<Employee> GetAllEmployees()
{
    ebll employeeBll = new EmployeeBLL();
    return ebll.GetAllEmployees().OrderBy(e => e.LastName).ToList();
}
T.S.
  • 18,195
  • 11
  • 58
  • 78
0

I agree with the answer that T.S. gave, however I would modify to return an IQueryable instead of returning the a .ToList() if you want to leave the option to further filter the list in the calling method. For example GetAllEmployees().Where(e=>e.Name="Brad") otherwise you are enumerating the list early and not taking advantage of using the underlying data source to do the heavy lifting of filtering therefore returning more data than is needed.

Brad Hess
  • 21
  • 2