https://github.com/olymo/doublel.queryablebuilder
🤘 Query-object based automatic predicate building, sorting and paging on top of IQueryable
https://github.com/olymo/doublel.queryablebuilder
database entity-framework entity-framework-core iqueryable query query-builder query-object
Last synced: 4 months ago
JSON representation
🤘 Query-object based automatic predicate building, sorting and paging on top of IQueryable
- Host: GitHub
- URL: https://github.com/olymo/doublel.queryablebuilder
- Owner: Olymo
- License: apache-2.0
- Created: 2020-07-20T18:05:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-03T11:38:11.000Z (5 months ago)
- Last Synced: 2025-02-03T12:26:52.561Z (5 months ago)
- Topics: database, entity-framework, entity-framework-core, iqueryable, query, query-builder, query-object
- Language: C#
- Homepage: https://github.com/Olymo/Doublel.QueryableBuilder
- Size: 58.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
 
## Queryable Builder for .NETThe idea behind quryable builder is simple - to reduce the amount of boilerplate query code in your codebase. It is designed around the idea of [query object](https://martinfowler.com/eaaCatalog/queryObject.html) and tries to further automate the process. You should simply design a class that will serve as a **query object**, decorate it with some of the predifined attributes, and, if needed, inherit from our base clasess and let the _**builder**_ to the heavy lifting of query composition.
In it's essence, it is a collection of extension methods for predicate building, sorting and paging on top of generic IQueryable interface. Based on your use-case, there are several options to choose from.
### Download & Install
**Nuget Package [Doublel.QueryableBuilder](https://www.nuget.org/packages/Doublel.QueryableBuilder/)**
```powershell
Install-Package Doublel.QueryableBuilder
```
OR
```powershell
dotnet add package Doublel.QueryableBuilder
```
Minimum Requirements: **.NET Standard 2.0**The tool was initialy designed for company's internal purposes, but we've figured out it could help someone else as well. If the example clicks for you, proceed to [building some queryes](https://github.com/Olymo/Doublel.QueryableBuilder/wiki/Building-Queries).
### Quick example
Let's say you have a user storage you would like to query and it's exposed via the IQueryable interface.First, you have your user class:
```cs
public class TestUser
{
public int Id { get; set; }
public string FirstName { get; set; }
public string Username { get; set; }
public int Age { get; set; }
}
```Then, you should define your **_query object_** class:
```cs
public class UserQuery
{
[QueryProperty]
public int? Age { get; set; }
[QueryProperties(ComparisonOperator.Contains, "FirstName", "Username")]
public string Keyword { get; set; }
}
```And finally, you query your datasource:
```cs
var queryObject = new UserQuery
{
Age = 20;
Keyword = "ma"
}
var users = new List { /* a bunch of users */}.AsQueryable();var result = users.BuildQuery(queryObject);
```
The resulting dataset will consist of all the users having being exactly 20 years old and containing string "ma" (case-insensitive) in either their Username of FirstName properties.