I coded two LINQ statements with different orderBy. Is there a way that I could change the orderBy without having to code twice like this:
if (param == "s")
{
var result = await db.PhraseCategories
.OrderBy(p => p.SortOrder)
.Select(p => new
{
Id = p.PhraseCategoryShortId,
Name = p.Name
})
.AsNoTracking()
.ToListAsync();
return Ok(result);
}
if (param == "n")
{
var result = await db.PhraseCategories
.OrderBy(p => p.Name)
.Select(p => new
{
Id = p.PhraseCategoryShortId,
Name = p.Name
})
.AsNoTracking()
.ToListAsync();
return Ok(result);
}