On LINQ to Entity, descending order does not work.

asp.net c# entity-framework linq linq-to-entities

Question

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();
1
3
4/15/2010 10:41:29 AM

Accepted Answer

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();
4
4/15/2010 12:03:10 PM

Popular Answer

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();


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow