Skip to content

Add ODataQueryOptions.TryValidate #1419

@KnapSac

Description

@KnapSac

There is currently no way to validate query options without throwing an exception. I'd like a TryValidate method, so I don't need to catch an exception to find out that the query options don't satisfy the settings. Ideally it would have an out parameter which includes the disallowed query option.

public ActionResult< IQueryable > Get(
	ODataQueryOptions< TResult > queryOptions )
{
	ODataValidationSettings validationSettings =
		new( )
		{
			AllowedQueryOptions = AllowedQueryOptions.Select | AllowedQueryOptions.SkipToken,
			MaxTop = 1000,
		};

	try
	{
		queryOptions.Validate( validationSettings );
	}
	catch ( Exception )
	{
		return BadRequest( "Unsupported query option" );
	}
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions