An open API service indexing awesome lists of open source software.

https://github.com/anton-grebenkin/queryfilter

a library that provides to apply serialized filters to IQueryable collections
https://github.com/anton-grebenkin/queryfilter

dotnet dotnet-core expressions filtering iqueryable library query-builder

Last synced: 20 days ago
JSON representation

a library that provides to apply serialized filters to IQueryable collections

Awesome Lists containing this project

README

          

# QueryFilter
A library that provides to apply serialized filters to IQueryable collections

## Features
- Filtering
- Paging
- Sorting

## Usage
Creating single filter with sorting and paging
```csharp
var filter = new Filter
{
MainNode = new FilterNode
{
ExpressionOperator = ExpressionOperatorType.GreaterThan,
PropertyName = nameof(Item.Id),
Value = 1
},
Sorts = new List()
{
new PropertySort
{
Desc = true,
PropertyName = nameof(Item.Id)
}
},
Skip = 10,
Take = 100
};

```

Creating multiple filters with a logical operator "or". It is possible to create many filters with nesting and logical operators "and" and "or"
```csharp
var filter = new Filter
{
MainNode = new FilterNode
{
LogicalOperator = LogicalOperatorType.Or,
FilterNodes = new List
{
new FilterNode
{
ExpressionOperator = ExpressionOperatorType.GreaterThan,
PropertyName = nameof(Item.Id),
Value = 1
},
new FilterNode
{
ExpressionOperator = ExpressionOperatorType.LessThan,
PropertyName = nameof(Item.Id),
Value = 100
}
}
},
Sorts = new List()
{
new PropertySort
{
Desc = true,
PropertyName = nameof(Item.Id)
}
},
Skip = 10,
Take = 100
};

```

Apply filter
```csharp
public ActionResult> GetItems([FromBody] Filter filter)
{
var items = db.Items.ApplyFilter(filter).ToList();
return Ok(items);
}
```