Order by descending is not working on LINQ to Entity

15,366

Solution 1

This should return correct result. It is working fine for me.

var hosters = 
from e in context.Hosters_HostingProviderDetail 
where e.ActiveStatusID == pendingStateId 
orderby e.HostingProviderName **descending**
select e; 

return hosters.ToList();

Solution 2

You could also use a lambda expression to get the same result:

return context.Hosters_HostingProviderDetail.Where(e => e.ActiveStatusID == pendingStateID).OrderByDescending(e => e.HostingProviderName).ToList();
Share:
15,366
Vinay Kumar Chella
Author by

Vinay Kumar Chella

I am an SDE in an MNC

Updated on June 04, 2022

Comments

  • Vinay Kumar Chella
    Vinay Kumar Chella almost 2 years

    Order by descending is not working on LINQ to Entity In the following Query In place of ascending If I keep descending it is not working. Please help me out

    var hosters =
        from e in context.Hosters_HostingProviderDetail
        where e.ActiveStatusID == pendingStateId
        orderby e.HostingProviderName ascending
        select e;
    
    return hosters.ToList();