Skip to content

DCCS-IT-Business-Solutions/DCCS.Data.Source

Repository files navigation

DCCS.Data.Source · Build Status NuGet Version

DCCS.Data.Source helps with automatic sorting and paging of data. It was created, to support Html-DataGrids with sorting and paging.

DCCS.Data.Source is supposed to get out of the programmers way and do as much as possible automaticly.

Installation

You should install DCCS.Data.Source with NuGet:

Install-Package DCCS.Data.Source

Or via the .NET Core command line interface:

dotnet add package DCCS.Data.Source

Either commands, from Package Manager Console or .NET Core CLI, will download and install DCCS.Data.Source and all required dependencies.

Examples

In this example we create an WebAPI action, that takes parameter (Params) for paging and sorting information, and returns the sorted and paged data (Result<T>).

public class UsersController : Controller
{
    public Result<User> Get(Params ps)
    {
        // ...get data i.e. from EF
        // data: IQueryable<User>
        return new Result<User>(ps, data);
    }
}

You can also use the IQueryable extension method.

    using DCCS.Data.Source;
    ...
    // data must be an IQueryable.
    return data.ToResult<User>();

The resulting JSON looks like this:

{
    "data": [
        {"name": "user 1", ...},
        {"name": "user 2", ...},
        // ...
    ],
    "page": 1,
    "count": 10,
    "orderBy": "name",
    "desc": false
}

You can skip sorting and paging if necessary:

return new Result<T>(ps, data, sort: false, page: false);

If you need to transform (Select) the sorted and paged data, you can use the Result<T>.Select method. Like this:

...

using(var db = new DbContext()) {
    var users = db.Users;
    return new Result(ps, users)
        .Select(user => new UserDTO(user));
}

Important: Only the paged data is transformed, so you can do this in combination with EF and it will work performantly with as many rows as your database can handle.

Contributing

License

DCCS.Data.Source is MIT licensed

About

Paing & Sorting of data made easy for WebAPI & Co.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published