| name | servicestack-autoquery |
| description | Implements AutoQuery services, custom filters, and permission-aware querying. |
ServiceStack AutoQuery
AutoQuery provides instant, queryable APIs from your OrmLite data models.
Basic Implementation
- Request DTO: Inherit from
QueryDb<TSource, TReturn>.
- Service: No implementation needed if inheriting from
QueryDb.
[Route("/customers/search")]
public class QueryCustomers : QueryDb<Customer> {}
Customizing Queries
- Properties as Filters: Add properties to the Request DTO to create automatic filters.
- Naming Conventions: Use
StartsWith, EndsWith, Greater, etc. (e.g., public int? IdGreater { get; set; }).
Custom Implementation (Logic)
If you need custom logic, implement the service and use GetQueryResponse:
public object Any(QueryCustomers request)
{
var q = AutoQuery.CreateQuery(request, Request);
q.And(c => c.IsActive);
return AutoQuery.Execute(request, q);
}
Security & Attributes
- Use
[Authenticate], [RequiredRole], etc., on the AutoQuery Request DTO.
- AutoQuery honors these attributes automatically.
Best Practices
- Explicit Routes: Always define a route for AutoQuery services.
- Limit Results: Use
DefaultLimit in AutoQueryFeature to prevent large payloads.
- Typed Filters: Prefer adding properties to the DTO over raw
q manipulation when possible for better metadata exposure.