Get Started

ServiceQuery is available as a NuGet package. You can download and install it using the .NET CLI or Visual Studio Package Manager Console.

Install NuGet Package:

ServiceQuery

Simple Database Access


    using ServiceQuery;

    // Get your Database Table/Collection as an IQueryable object
    var queryable = databaseContext.ExampleTable.AsQueryable();

    // Build a request using the ServiceQueryRequestBuilder object
    var request = new ServiceQueryRequestBuilder().Build();

    // Execute the request against the database and get the results
    var response = request.Execute(queryable);
        

Use in a REST API


    using ServiceQuery;

    [HttpPost]
    [Route("ExampleQuery")]
    public ServiceQueryResponse ExampleQuery(ServiceQueryRequest request)
    {
        var queryable = databaseContext.ExampleTable.AsQueryable();
        return request.Execute(queryable);
    }
        

Use in JavaScript/jQuery

Include servicequery.js in your project.


    
    
        

Building Queries


    // Default paging settings
    var request = new ServiceQueryRequestBuilder().Build();
    request = new ServiceQueryRequestBuilder().Paging(1, 1000, false).Build();

    // Count records with response
    request = new ServiceQueryRequestBuilder().IsGreaterThan("id","10").IncludeCount().Build();

    // Selecting specific properties
    request = new ServiceQueryRequestBuilder().Select("Id","FirstName","LastName").Build();

    // Build AND/OR expressions
    request = new ServiceQueryRequestBuilder().IsEqual("Id","1").And().StartsWith("FirstName", "John").Build();
    request = new ServiceQueryRequestBuilder().Between("Id","1", "5").Or().Contains("LastName", "Smith").Build();

    // Grouped expressions with nesting
    request = new ServiceQueryRequestBuilder()
        .Begin()
            .IsEqual("Id","1")
            .And()
            .IsInSet("Status", "Created", "Open", "InProcess")
        .End()
        .Or()
        .Begin()
            .IsLessThanOrEqual("BirthDate","1/1/2000")
            .And()
            .IsNull("CloseDate")
        .End().Build();

    // Sorting
    request = new ServiceQueryRequestBuilder().IsEqual("Age", "21").SortAsc("FirstName").Build();

    // Aggregates
    request = new ServiceQueryRequestBuilder().IsLessThan("Id", "200").Sum("Price").Build();