DynamicLinqSearch 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DynamicLinqSearch --version 1.0.0                
NuGet\Install-Package DynamicLinqSearch -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DynamicLinqSearch" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DynamicLinqSearch --version 1.0.0                
#r "nuget: DynamicLinqSearch, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DynamicLinqSearch as a Cake Addin
#addin nuget:?package=DynamicLinqSearch&version=1.0.0

// Install DynamicLinqSearch as a Cake Tool
#tool nuget:?package=DynamicLinqSearch&version=1.0.0                

Expression Helper

Expression helper, translates your written rules into a dynamic query.

Usage

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }

    public Product(int id, string name, decimal price)
    {
        Id = id;
        Name = name;
        Price = price;
    }
}

Let's assume you have a product model.

var products = new List<Product>
{
    new Product(1, "Keyboard", 500),
    new Product(2, "Mouse", 700),
    new Product(3, "Ram", 2000),
    new Product(4, "Speaker", 1000),
    new Product(5, "Monitor", 3000)
};

Let's create a filtering model to generate dynamic queries for your product listings.

List<FilterQuery> rules = new List<FilterQuery>()
{
    new FilterQuery()
    {
        Column = "Name",
        Condition = "Keyboard",
        Relation = RuleRelation.Contains,
        Statement = "Or"
    },
    new FilterQuery()
    {
        Column = "Name",
        Condition = "Mouse",
        Relation = RuleRelation.Contains,
        Statement = "Or"
    },
    new FilterQuery()
    {
        Column = "Price",
        Condition = "1000",
        Relation = RuleRelation.LessThan,
        Statement = "And"
    }
};

Let's send this model to our function that generates dynamic queries.

var filter = ExpressionHelper.BuildDynamicFilter<Product>(rules);

The result of the "filter" variable is:

x => x.Name.Contains("Keyboard") || x.Name.Contains("Mouse") && x.Price <= 1000

Summary:

var filter = ExpressionHelper.BuildDynamicFilter<Product>(rules);
var results = queryable.Where(filter).ToList();

Result:

[
    {
	    "id":  1,
	    "name":  "Keyboard",
	    "price":  500
    },
    {
	    "id":  2,
	    "name":  "Mouse",
	    "price":  700
    }
]
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 254 10/20/2023
1.1.0 135 10/17/2023
1.0.0 111 10/6/2023

Created dynamic linq and string column search methods.