// ASP.NET Core calls this to validate the incoming parameters public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var processor = new SortOptionsProcessor <T, TEntity>(Sort); var validTerms = processor.GetValidTerms().Select(x => x.Name); var invalidTerms = processor.GetAllTerms().Select(x => x.Name) .Except(validTerms, StringComparer.OrdinalIgnoreCase); foreach (var term in invalidTerms) { yield return(new ValidationResult( $"Invalid sort term '{term}'.", new[] { nameof(Sort) })); } }
// The service code will call this to apply these sort options to a database query public IQueryable <TEntity> Apply(IQueryable <TEntity> query) { var processor = new SortOptionsProcessor <T, TEntity>(Sort); return(processor.Apply(query)); }