{"id":36924113,"url":"https://github.com/zHaytam/DynamicExpressions","last_synced_at":"2026-01-19T18:00:41.356Z","repository":{"id":45687841,"uuid":"264518397","full_name":"zHaytam/DynamicExpressions","owner":"zHaytam","description":"A dynamic expression builder that can be used to dynamically sort and/or filter LINQ/EF queries","archived":false,"fork":false,"pushed_at":"2021-11-14T22:33:23.000Z","size":36,"stargazers_count":55,"open_issues_count":4,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-29T04:26:23.347Z","etag":null,"topics":["expression-trees","filtering","netstandard","sorting"],"latest_commit_sha":null,"homepage":"https://blog.zhaytam.com/2020/05/17/dynamic-sorting-filtering-csharp/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zHaytam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-16T20:10:10.000Z","updated_at":"2025-06-27T10:20:02.000Z","dependencies_parsed_at":"2022-09-16T18:40:23.303Z","dependency_job_id":null,"html_url":"https://github.com/zHaytam/DynamicExpressions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zHaytam/DynamicExpressions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zHaytam%2FDynamicExpressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zHaytam%2FDynamicExpressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zHaytam%2FDynamicExpressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zHaytam%2FDynamicExpressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zHaytam","download_url":"https://codeload.github.com/zHaytam/DynamicExpressions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zHaytam%2FDynamicExpressions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28578952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T17:42:58.221Z","status":"ssl_error","status_checked_at":"2026-01-19T17:40:54.158Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expression-trees","filtering","netstandard","sorting"],"created_at":"2026-01-12T19:00:25.486Z","updated_at":"2026-01-19T18:00:41.345Z","avatar_url":"https://github.com/zHaytam.png","language":"C#","readme":"# DynamicExpressions\n\nA dynamic expression builder that can be used to dynamically sort and/or filter LINQ/EF queries.  \nI wrote a blog post that explains the usage \u0026 benefits, check it out [here](https://blog.zhaytam.com/2020/05/17/dynamic-sorting-filtering-csharp/).\n\nThis 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.\n\n||Badges|\n|--|--|\n|NuGet|[![NuGet](https://img.shields.io/nuget/v/DynamicExpressions.NET.svg)](https://www.nuget.org/packages/DynamicExpressions.NET) [![Nuget](https://img.shields.io/nuget/dt/DynamicExpressions.NET.svg)](https://www.nuget.org/packages/DynamicExpressions.NET)|\n|License|[![GitHub](https://img.shields.io/github/license/zHaytam/DynamicExpressions.svg)](https://github.com/zHaytam/DynamicExpressions)|\n\n## Property Getters\n\nThis is usually used when you want to do an `OrderBy` or `OrderByDescending`.  \nFor example:\n\n```cs\n_dbContext.Products.AsQueryable().OrderBy(p =\u003e p.Price);\n```\n\nIf 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.\n\nUsing this library, you can simply do this:\n\n```cs\nvar propertyGetter = DynamicExpressions.GetPropertyGetter\u003cProduct\u003e(propertySentByUser);\n// ^ can be cached or even compiled to a Func\u003cProduct, object\u003e\nvar query = _dbContext.Products.AsQueryable().OrderBy(propertyGetter);\n// Or OrderByDesceding\n```\n\nAnd it will handle all the properties, unless you do a pre-validation.\n\n## Predicates\n\n### Simple\n\nPredicates in c# are functions that take one or more parameter and returns a boolean.  \nFor example, when you want to filter an `IQueryable`, you use a `Func\u003cTEntity, bool\u003e`.\n\nFor example:\n```cs\n_dbContext.Products.AsQueryable().Where(p =\u003e p.Name.Contains(termSentByUser));\n```\n\nAgain, this only handles a `Contains` filter on the `Name` property.  \nThe more properties and operators you have, the more \"boring\" code you'll need to write.\n\nUsing this library, you can simple do this:\n\n```cs\nvar predicate = DynamicExpressions.GetPredicate\u003cProduct\u003e(propertySentByUser, operatorSentByUser, valueSentByUser);\n// ^ can also be cached or compiled and used anywhere\nvar products = _dbContext.Products.AsQueryable().Where(predicate).ToList();\n// ^ or FirstByDefault, Any, etc...\n```\n\n### Advanced\n\nIn the previous example, we filtered products only on their price. We will now see how we can create advnaced dynamic predicates.\n\nLet's say for example you want to create the following filter:\n\n```cs\nProduct.Enabled\n\u0026\u0026 (Product.Brand == \"Nike\" || Product.Brand == \"Adidas\")\n\u0026\u0026 (Product.Price \u003e= 20 \u0026\u0026 Product.Price \u003c= 100)\n```\n\nUsing this library, you're able to do this:\n\n```cs\nvar predicate = new DynamicFilterBuilder\u003cProduct\u003e()\n  .And(\"Enabled\", FilterOperator.Equals, true)\n  .And(b =\u003e b.And(\"Brand\", FilterOperator.Equals, \"Nike\").Or(\"Brand\", FilterOperator.Equals, \"Adidas\"))\n  .And(b =\u003e b.And(\"Price\", FilterOperator.GreaterThanOrEqual, 20).And(\"Price\", FilterOperator.LessThanOrEqual, 100))\n  .Build();\n  \nvar products = _dbContext.Products.AsQueryable().Where(predicate).ToList();\n```\n\nOf course, everything can be configurable and provided by the user.  \nA 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`.\n\n## Feedback\n\nIf you find a bug or you want to see a functionality in this library, feel free to open an issue in the repository!  \nOf course, PRs are very welcome.\n","funding_links":[],"categories":["C# #"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzHaytam%2FDynamicExpressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FzHaytam%2FDynamicExpressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzHaytam%2FDynamicExpressions/lists"}