Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a List of Student which I am getting from table Student.
In that table I have two column IsTopper and IsLoser both are bool.
Now in listOfStudent I want IsTopper at top and Is loser at bottom
for this I can use Orderby
Like this
C#
public List<Student> GetAllStudent()
        {
            return unitOfWork.StudentRepository.All().OrderBy(s => s.IsLoser ).OrderByDescending(s => s.IsTopper).ToList();
        }

it will hurt performance
is there any other way to get isTopper at top and is Loser at bottom?
Posted
Updated 17-Nov-14 4:19am
v2
Comments
Kornfeld Eliyahu Peter 17-Nov-14 9:59am    
Why should order by hurt the performance?
Can we see your exact query? There may be an error with it...
Nathan Minier 17-Nov-14 10:16am    
Agreed. Unless your SQL server is held together with paperclips, applying an OrderBy BEFORE you enumerate your IQueryable should not impact performance notably.

Of course, if you're genuinely concerned about it, you could just do that sorting on the client, giving you a filtering functionality.
Vishal Pand3y 17-Nov-14 10:20am    
@Kornfeld Eliyahu Peter I have Updated My question
DamithSL 17-Nov-14 11:32am    
how about
unitOfWork.StudentRepository.OrderBy(s => s.IsLoser ).ThenByDescending(s => s.IsTopper).ToList()
Vishal Pand3y 18-Nov-14 1:52am    
I Need to use All() as I want list of all student and is there much deference between OrderByDescending() and ThenByDescending()

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