<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Phúc Nguyễn</title>
    <description>The latest articles on DEV Community by Phúc Nguyễn (@phucthanh6554).</description>
    <link>https://dev.to/phucthanh6554</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2041717%2Fcff7c2ab-9637-4c5a-b471-d6f291da2897.png</url>
      <title>DEV Community: Phúc Nguyễn</title>
      <link>https://dev.to/phucthanh6554</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phucthanh6554"/>
    <language>en</language>
    <item>
      <title>A Flexible Way to Filter Your IQueryable in .NET</title>
      <dc:creator>Phúc Nguyễn</dc:creator>
      <pubDate>Tue, 08 Jul 2025 09:54:46 +0000</pubDate>
      <link>https://dev.to/phucthanh6554/a-flexible-way-to-filter-your-iqueryable-in-net-3oh5</link>
      <guid>https://dev.to/phucthanh6554/a-flexible-way-to-filter-your-iqueryable-in-net-3oh5</guid>
      <description>&lt;p&gt;Filtering data dynamically in a clean and reusable way is often a common challenge in .NET applications—especially when working with complex APIs or building search interfaces.&lt;/p&gt;

&lt;p&gt;This Nuget package will help you build powerful and flexible filtering logic using C# Expression Trees.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;em&gt;dotnet-dynamic-filter-expression&lt;/em&gt;?
&lt;/h2&gt;

&lt;p&gt;Packge &lt;strong&gt;dotnet-dynamic-filter-expression&lt;/strong&gt; allows you to dynamically build LINQ IQueryable filters based on runtime conditions, such as query parameters from APIs or user-generated filters from front-end applications.&lt;/p&gt;

&lt;p&gt;The goal is to eliminate boilerplate filtering logic and make your code more declarative and maintainable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use It?
&lt;/h2&gt;

&lt;p&gt;✔ Dynamic &amp;amp; Composable: Build filters at runtime using expression trees.&lt;/p&gt;

&lt;p&gt;✔ Strongly Typed: Safe and type-checked filtering for your entity models.&lt;/p&gt;

&lt;p&gt;✔ Minimal Setup: Add the NuGet package, define your conditions, and apply filters—it’s that simple.&lt;/p&gt;

&lt;p&gt;✔ Clean API: Designed to feel natural to .NET developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package dotnet-dynamic-filter-expression
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example Usage
&lt;/h2&gt;

&lt;p&gt;Suppose you have these Customer and EmailAddress classes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public Datetime BirthDay { get; set; }
    public EmailAddress Email { get; set; }
}

public class EmailAddress 
{
    public string Address { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can build dynamic filter like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using FilterExpression;
using FilterExpression.Extension;

var list = new List&amp;lt;Customer&amp;gt;
{
    new Customer{ Name = "Name 1", Age = 25, Id = 1, BirthDay = new DateTime(1997, 9, 15), Email = new EmailAddress {Address = "email1@gmail.com} },

    new Customer{ Name = "Name 2", Age = 35, Id = 2, BirthDay = new DateTime(1990, 1, 1), Email = new EmailAddress {Address = "email2@gmail.com} },

    new Customer{ Name = "Name 3", Age = 15, Id = 3, BirthDay = new DateTime(2000, 5, 1),Email = new EmailAddress {Address = "email3@gmail.com}  },
};

var filterService = new FilterService();
var filter = filterService.Filter&amp;lt;Customer&amp;gt;("(Name eq `Name 1`)");

var filteredList = list.Where(filter.Compile()).ToArray();

// Another way
var filteredList = list.Filter("((Name contains `Name`) &amp;amp; (Age lt `30`))");

// Supported for IQueryable
var filteredList = list.AsQueryable().Filter("(BirthDay le `1997-9-15`)").ToList();

// Supported for nested object
var filteredList = list.AsQueryable().Filter("(Email.Address eq `email2@gmail.com`)").ToList();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Supported Operators
&lt;/h2&gt;

&lt;p&gt;dotnet-dynamic-filter-expression supports a wide range of comparison operators out of the box, including:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Equal: (Name eq `John Doe`)
- Not Equal: (Name ne `John Doe`)
- Greater than: (Age gt `25`)
- Greater than and equal (Age ge `25`)
- Less than: (Age lt `25`)
- Less than and equal (Age le `25`)
- Contains: (Name contains `P`)
- StartsWith: (Name StartsWith `P`)
- In: (Age in `[25, 26]`)
- And: ( (Age eq `25`) &amp;amp; (Name eq `John`))
- Or: ( (Age eq `25`) | (Name eq `John`))
- Not: !(Name eq `John Doe`)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also extend it with your own custom operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  This package ideal for
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Building admin dashboards with flexible filtering&lt;/li&gt;
&lt;li&gt;Creating search APIs with user-defined criteria&lt;/li&gt;
&lt;li&gt;Eliminating repetitive Where(...) logic in services&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Under the Hood
&lt;/h2&gt;

&lt;p&gt;The library uses expression trees to build strongly-typed lambda expressions that are directly compatible with IQueryable. This ensures performance and compatibility with LINQ providers such as Entity Framework Core.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback &amp;amp; Contributions
&lt;/h2&gt;

&lt;p&gt;This is an open-source project and still evolving. I’d love to hear your feedback, issues, or ideas to make it better.&lt;/p&gt;

&lt;p&gt;👉 GitHub Repository: &lt;a href="https://github.com/phucthanh6554/dotnet-dynamic-filter-expression" rel="noopener noreferrer"&gt;https://github.com/phucthanh6554/dotnet-dynamic-filter-expression&lt;/a&gt;&lt;br&gt;
📦 NuGet: &lt;a href="https://www.nuget.org/packages/dotnet-dynamic-filter-expression" rel="noopener noreferrer"&gt;https://www.nuget.org/packages/dotnet-dynamic-filter-expression&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
