Entity Framework Core - Sorting

c# entity-framework-core sorting

Popular Answer

In addition to the missing break, the sort assignment is also lacking.

public async Task<ICollection<Article>> SortArticles(string sortOrder)
{
    IQueryable<Article> articles = GetAll();
    switch (sortOrder)
    {
        case "name_desc": 
            articles = articles.OrderByDescending(s => s.Name).AsQueryable();           
        break;
        case "date":
            articles = articles.OrderBy(s => s.DateCreated).AsQueryable();
            break;
        case "date_desc":
            articles = articles.OrderByDescending(s => s.DateCreated).AsQueryable();
            break;
        default:
             articles = articles.OrderBy(s => s.Name).AsQueryable();
            break;
    }
    var result = await articles.ToListAsync();
    return result;
}
0
8/23/2018 10:20:31 PM


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