Establish scope
Authenticate the caller and apply ownership, tenant, lifecycle, or other server-owned filters.

Integration examples
See how ServiceQuery® fits inside real endpoints with server-owned scope, field policy, operational limits, observability, and tenant isolation.
Flexible queries. Deliberate boundaries.
A bounded integration path
A useful endpoint separates client intent from server authority and provider execution.
Authenticate the caller and apply ownership, tenant, lifecycle, or other server-owned filters.
Allow only the fields and operations that make sense for this endpoint.
Set page-size, complexity, sort, rate, and business limits before execution.
Run the request over the queryable source selected by the API.
Record useful normalized query information without treating raw client input as trusted evidence.
Scope before query
Dynamic querying does not replace authorization or tenant isolation. Establish the base query first, then execute the client request against that scoped source.
Ownership and lifecycle
var baseQuery = db.Orders
.Where(order => order.UserId == userId)
.Where(order => !order.IsDeleted);
return Results.Ok(request.Execute(baseQuery));
Tenant isolation
var baseQuery = db.Items
.Where(item => item.TenantId == tenantId);
return Results.Ok(request.Execute(baseQuery));
Define the query surface
A structured request is not permission by itself. Use an API-owned policy to reject fields and operations that do not belong on the endpoint.
var allowedFields = new HashSet<string>
{
"Name",
"Status",
"CreatedAt"
};
var requested = request.Filters
.SelectMany(filter => filter.Properties ?? Enumerable.Empty<string>())
.Distinct(StringComparer.OrdinalIgnoreCase);
var disallowed = requested
.Except(allowedFields, StringComparer.OrdinalIgnoreCase);
if (disallowed.Any()) return BadRequest();
Salary when the endpoint policy does not allow them.ServiceQuery provides the structured query path. The API remains the authority over the exposed data contract.
Bound the work
Page size, filter depth, sort count, rate limits, and business rules help keep a flexible endpoint predictable to operate.
var pageSizeFilter = request.Filters.FirstOrDefault(filter =>
string.Equals(filter.FilterType, "pagesize", StringComparison.OrdinalIgnoreCase) ||
string.Equals(filter.FilterType, "ps", StringComparison.OrdinalIgnoreCase));
if (pageSizeFilter is not null &&
(!int.TryParse(pageSizeFilter.Values.FirstOrDefault(), out var pageSize) || pageSize > 100))
{
return Results.BadRequest("Page size cannot exceed 100");
}
Observe the normalized request
Useful observability describes fields, operators, and limits without treating raw client text as trusted or necessary log content.
var fields = request.Filters
.SelectMany(filter => filter.Properties ?? Enumerable.Empty<string>())
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToArray();
logger.LogInformation(
"Query: Fields={Fields}, Filters={FilterCount}",
fields,
request.Filters.Count);
A complete bounded endpoint
The implementation is small. The important part is preserving the order of authority, policy, execution, and observation around it.
var request = new ServiceQueryRequestBuilder()
.IsEqual("Status", "Active")
.SortDesc("CreatedAt")
.Paging(1, 25, true)
.Build();
var scopedQuery = db.Products
.Where(product => product.TenantId == tenantId)
.Where(product => !product.IsDeleted);
return Results.Ok(request.Execute(scopedQuery));
Inspect. Run. Adopt.
Start with the request model, review the security boundary, and apply the integration pattern to an API you control.