In my .NET Core / EF Core application I have a model with a nested list of child objects. When I retrieve an instance, I need the nested list to be ordered by one of the child's properties.
What is the correct way to sort this list so that it always returns sorted correctly from my database?
Right now I do it after loading from database:
public async Task<Parent> GetParent(int id)
{
var result = await context.Parents
.Include(p => p.Children)
.SingleOrDefaultAsync(p => p.Id == id);
result.Children = result.Children.OrderBy(c => c.Sequence).ToList();
return result;
}