All Projects → zHaytam → DynamicExpressions

zHaytam / DynamicExpressions

Licence: MIT License
A dynamic expression builder that can be used to dynamically sort and/or filter LINQ/EF queries

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to DynamicExpressions

Feedly Filtering And Sorting
Enhance the feedly website with advanced filtering and sorting capabilities
Stars: ✭ 73 (+151.72%)
Mutual labels:  sorting, filtering
Vuejs Datatable
A Vue.js component for filterable and paginated tables.
Stars: ✭ 148 (+410.34%)
Mutual labels:  sorting, filtering
Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (+162.07%)
Mutual labels:  sorting, filtering
ember-sort-filter-table
A sortable/searchable table addon for ember cli
Stars: ✭ 13 (-55.17%)
Mutual labels:  sorting, filtering
Blazortable
Blazor Table Component with Sorting, Paging and Filtering
Stars: ✭ 249 (+758.62%)
Mutual labels:  sorting, filtering
ag-grid
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
Stars: ✭ 8,743 (+30048.28%)
Mutual labels:  sorting, filtering
pimpable
No description or website provided.
Stars: ✭ 102 (+251.72%)
Mutual labels:  sorting, filtering
Flatlist React
A helpful utility component to handle lists in react like a champ
Stars: ✭ 34 (+17.24%)
Mutual labels:  sorting, filtering
JqueryDataTablesServerSideDemo
Jquery DataTables with Asp.Net Core server side multi column sorting and searching Demo Project.
Stars: ✭ 43 (+48.28%)
Mutual labels:  sorting, filtering
React Table
⚛️ Hooks for building fast and extendable tables and datagrids for React
Stars: ✭ 15,739 (+54172.41%)
Mutual labels:  sorting, filtering
Vue Table Dynamic
🎉 A dynamic table with sorting, filtering, editing, pagination, multiple select, etc.
Stars: ✭ 106 (+265.52%)
Mutual labels:  sorting, filtering
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+1182.76%)
Mutual labels:  sorting, filtering
Vue Bootstrap4 Table
Advanced table based on Vue 2 and Bootstrap 4 ⚡️
Stars: ✭ 187 (+544.83%)
Mutual labels:  sorting, filtering
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (+65.52%)
Mutual labels:  sorting, filtering
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (+141.38%)
Mutual labels:  sorting, filtering
type-comparator
Useful comparator functions written on Typescript
Stars: ✭ 56 (+93.1%)
Mutual labels:  sorting
openmessaging.github.io
OpenMessaging homepage
Stars: ✭ 12 (-58.62%)
Mutual labels:  filtering
directed graph
Dart implementation of a directed graph. Provides algorithms for sorting vertices, retrieving a topological ordering or detecting cycles.
Stars: ✭ 37 (+27.59%)
Mutual labels:  sorting
big-sorter
Java library that sorts very large files of records by splitting into smaller sorted files and merging
Stars: ✭ 49 (+68.97%)
Mutual labels:  sorting
ReflectionBridge
ReflectionBridge : Provides some extensions which define a bridge for the differences between Type and TypeInfo.
Stars: ✭ 25 (-13.79%)
Mutual labels:  netstandard

DynamicExpressions

A dynamic expression builder that can be used to dynamically sort and/or filter LINQ/EF queries.
I wrote a blog post that explains the usage & benefits, check it out here.

This library tries to generate Expression Trees as close to the one generated by c# as possible, so in almost all cases, you don't even need to worry about performance.

Badges
NuGet NuGet Nuget
License GitHub

Property Getters

This is usually used when you want to do an OrderBy or OrderByDescending.
For example:

_dbContext.Products.AsQueryable().OrderBy(p => p.Price);

If you want to give the ability for the user to choose what to order by, you'll need to do a switch statement with all the possible values, which can be exhausting, especially if it's for multiple entities.

Using this library, you can simply do this:

var propertyGetter = DynamicExpressions.GetPropertyGetter<Product>(propertySentByUser);
// ^ can be cached or even compiled to a Func<Product, object>
var query = _dbContext.Products.AsQueryable().OrderBy(propertyGetter);
// Or OrderByDesceding

And it will handle all the properties, unless you do a pre-validation.

Predicates

Simple

Predicates in c# are functions that take one or more parameter and returns a boolean.
For example, when you want to filter an IQueryable, you use a Func<TEntity, bool>.

For example:

_dbContext.Products.AsQueryable().Where(p => p.Name.Contains(termSentByUser));

Again, this only handles a Contains filter on the Name property.
The more properties and operators you have, the more "boring" code you'll need to write.

Using this library, you can simple do this:

var predicate = DynamicExpressions.GetPredicate<Product>(propertySentByUser, operatorSentByUser, valueSentByUser);
// ^ can also be cached or compiled and used anywhere
var products = _dbContext.Products.AsQueryable().Where(predicate).ToList();
// ^ or FirstByDefault, Any, etc...

Advanced

In the previous example, we filtered products only on their price. We will now see how we can create advnaced dynamic predicates.

Let's say for example you want to create the following filter:

Product.Enabled
&& (Product.Brand == "Nike" || Product.Brand == "Adidas")
&& (Product.Price >= 20 && Product.Price <= 100)

Using this library, you're able to do this:

var predicate = new DynamicFilterBuilder<Product>()
  .And("Enabled", FilterOperator.Equals, true)
  .And(b => b.And("Brand", FilterOperator.Equals, "Nike").Or("Brand", FilterOperator.Equals, "Adidas"))
  .And(b => b.And("Price", FilterOperator.GreaterThanOrEqual, 20).And("Price", FilterOperator.LessThanOrEqual, 100))
  .Build();
  
var products = _dbContext.Products.AsQueryable().Where(predicate).ToList();

Of course, everything can be configurable and provided by the user.
A more real life example would be for the frontend (user) to give you a list of filters that you can dynamically apply using a DynamicFilterBuilder.

Feedback

If you find a bug or you want to see a functionality in this library, feel free to open an issue in the repository!
Of course, PRs are very welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].