SearchQuery 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SearchQuery --version 1.0.1
                    
NuGet\Install-Package SearchQuery -Version 1.0.1
                    
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="SearchQuery" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SearchQuery" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SearchQuery" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SearchQuery --version 1.0.1
                    
#r "nuget: SearchQuery, 1.0.1"
                    
#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.
#addin nuget:?package=SearchQuery&version=1.0.1
                    
Install SearchQuery as a Cake Addin
#tool nuget:?package=SearchQuery&version=1.0.1
                    
Install SearchQuery as a Cake Tool

SearchQuery

SearchQuery is a library that extends LINQ-based search capabilities over a database using Entity Framework. It is designed to be database-agnostic and integrates seamlessly with your existing code and data. The library supports flexible and efficient search operations through IQueryable and IEnumerable interfaces.

Key Features

  • Flexible Search: Supports complex search queries with logical operators (And, Or) and multiple conditions.
  • Database Agnostic: Works with any database supported by Entity Framework.
  • JSON Integration: Allows search queries to be defined in JSON format for easier frontend-backend communication.
  • Pagination: Built-in support for paginated results.
  • Type Safety: Handles various data types like strings, numbers, dates, and booleans.

Installation

.NET

Install the SearchQuery package via NuGet:

dotnet add package SearchQuery

JavaScript/TypeScript

Install the SearchQuery package via npm:

npm install jsearchquery

Requirements

  • .NET: Minimum version required is .NET 6.0.

Usage Examples

JavaScript/TypeScript

import { SearchQuery, Operator, Operation, Case } from "jsearchquery";

const search = new SearchQuery({
  operator: Operator.And,
  conditions: [
    {
      field: "fullName",
      operation: Operation.Equal,
      values: ["Dennis Ritchie"],
    },
    {
      field: "created",
      operation: Operation.Between,
      values: ["1990-12-31", "2025-12-31"],
    },
    {
      operator: Operator.Or,
      conditions: [
        {
          field: "fullName",
          operation: Operation.StartsWith,
          values: ["Dennis"],
          incase: Case.Lower,
        },
        {
          field: "fullName",
          operation: Operation.EndsWith,
          values: ["Ritchie"],
          incase: Case.Upper,
        },
      ],
    },
  ],
});

C#

using SearchQuery;

var searchQuery = new Search
{
    Operator = Operator.And,
    Conditions = new Conditions {
        new Condition
        {
            Field = nameof(TestEntity.FullName),
            Operation = Operation.Equal,
            Values = new Values { "Dennis Ritchie" }
        },
        new Condition
        {
            Field = nameof(TestEntity.Created),
            Operation = Operation.Between,
            Values = new Values { "1990-12-31", "2025-12-31" }
        },
        new Query {
            Operator = Operator.Or,
            Conditions = new Conditions {
                new Condition
                {
                    Field = nameof(TestEntity.FullName),
                    Operation = Operation.StartsWith,
                    Values = new Values { "Dennis" },
                    Incase = Case.Lower
                },
                new Condition
                {
                    Field = nameof(TestEntity.FullName),
                    Operation = Operation.EndsWith,
                    Values = new Values { "Ritchie" },
                    Incase = Case.Upper
                }
            }
        }
    }
};

using (var db = new Database())
{
    var results = db.Entities.Search(searchQuery).ToList();
}

API Overview

Namespace: SearchQuery

Search Methods

For IEnumerable

public static IEnumerable<T> Search<T>(this IEnumerable<T> set, Search query) where T : class;
public static IEnumerable<T> Search<T>(this IEnumerable<T> set, Search query, int pageNumber, int pageSize) where T : class;

For IQueryable

public static IQueryable<T> Search<T>(this IQueryable<T> set, Search query) where T : class;
public static IQueryable<T> Search<T>(this IQueryable<T> set, Search query, int pageNumber, int pageSize) where T : class;
JSON Search Methods

Convert JSON to Search Query

public static JSearch ToSearch(this string json);

Search Using JSON

public static IEnumerable<T> Search<T>(this IEnumerable<T> set, string query) where T : class;
public static IQueryable<T> Search<T>(this IQueryable<T> set, string query) where T : class;

Data Types Mapping

JavaScript/TypeScript .NET Type Supported .NET Types
string string string
Date, string string DateTime, string
number number char, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal
boolean boolean bool
null/undefined null null

Enum Definitions

Operation

Defines the operations that can be applied to fields.

Operation Description
Equal Checks for equality.
NotEqual Checks for inequality.
LessThan Checks if less than.
GreaterThan Checks if greater than.
Contains Checks if contains a value.
Between Checks if within a range.

Operator

Defines logical operators for combining conditions.

Operator Description
And Logical AND
Or Logical OR

Case

Defines case sensitivity for string operations.

Case Description
Default Case-insensitive.
Lower Converts to lowercase.
Upper Converts to uppercase.

Notes

  • Ensure JSON queries follow valid JSON format.
  • Use appropriate data types for fields to avoid runtime errors.
  • Pagination parameters (pageNumber, pageSize) are optional.

License

This project is licensed under the MIT License.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.1.1 54 4/5/2025
1.0.1 46 4/5/2025
1.0.0.4 77 12/21/2024
1.0.0.3 73 12/20/2024
1.0.0.2 69 12/20/2024
1.0.0.1 70 12/19/2024
1.0.0 67 12/19/2024