Get Started
Install Service Query into your project using the NuGet instructions on the right. It supports the following Microsoft Frameworks:
- .NET 7
- .NET 6
- .NET Standard 2.1
- .NET Standard 2.0 (no async support)
- .NET Standard 1.3 (no async support)
- .NET 4.5 (no async support)
- .NET 4.0 (no async support)
- .NET 3.5 (no async support)
Service Query supports most SQL and NoSQL database engines or just a bunch of objects in a list! There are 3 core concepts:
- Get an IQueryable interface to your table, collection or list of objects
- Creating/Receive a ServiceQueryRequest object
- Execute the ServiceQueryRequest object
Using ServiceQuery in a REST API service:
[HttpPost]
[Route("ServiceQuery")]
public ServiceQueryResponse<ExampleTable> ServiceQuery(ServiceQueryRequest request)
{
if (request == null)
return null;
var queryable = _context.ExampleTable.AsQueryable();
return request.Execute(queryable);
}
Consuming a ServiceQuery API with JQuery (Front End):
If you are calling Service Query from a front end with javascript/JQuery, download the servicequery.js file. This javascript file contains a ServiceQueryRequestBuilder class that uses the same syntax as the .NET Framework code!
<script type="text/javascript">
function GetAll() {
var request = new ServiceQueryRequestBuilder().Build();
$.ajax({
url: '/api/Example/ServiceQuery',
data: JSON.stringify(request),
type: "POST",
dataType: 'json',
headers: { 'Content-Type': 'application/json' },
success: function (result) {
alert(result.list.length + ' records returned');
}
});
}
</script>
Instructions to Install
Install the NuGet library ServiceQuery
If you are calling Service Query from a front end with javascript/JQuery, download the servicequery.js file. This javascript file contains a ServiceQueryRequestBuilder class that uses the same syntax as the .NET Framework code!
NuGet Package Instructions
Package Manager
.NET CLI
Visual Studio
Usage
// Get Database Table as IQueryable
var queryable = context.ExampleTable.AsQueryable();
// Build a ServiceQueryRequest
var request = ServiceQueryRequestBuilder.New().Build();
// Execute the request sync
var response = request.Execute(queryable);
// Execute the request async
var responseAsync = await request.ExecuteAsync(queryable);