SearchQuery 1.0.0.3
See the version list below for details.
dotnet add package SearchQuery --version 1.0.0.3
NuGet\Install-Package SearchQuery -Version 1.0.0.3
<PackageReference Include="SearchQuery" Version="1.0.0.3" />
<PackageVersion Include="SearchQuery" Version="1.0.0.3" />
<PackageReference Include="SearchQuery" />
paket add SearchQuery --version 1.0.0.3
#r "nuget: SearchQuery, 1.0.0.3"
#:package SearchQuery@1.0.0.3
#addin nuget:?package=SearchQuery&version=1.0.0.3
#tool nuget:?package=SearchQuery&version=1.0.0.3
SearchQuery
SearchQuery is a library that extends LINQ search over a database using Entity Framework. SearchQuery isn't tied to any specific database or storage engine and is instead backed by your existing code and data. Search can be done in two interfaces IQueryable, IEnumerable.
The main task is to make the request between Frontend - Backend more flexible and easier to search data.
Info Minimal version is .NET 6.0
npm install jsearchquery
dotnet add package SearchQuery
Warning Important to follow valid json format and type for request condition field type.
Types
A SearchQuery object type at some point those fields have to resolve to some concrete data.
| SearchQuery JS/TS | SearchQuery .NET | .NET |
|---|---|---|
| string | string | string |
| Date | string | DateTime |
| number | number | char, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal |
| boolean | boolean | boolean |
| null/undefined | null | null |
Examples
JavaScript/TypeScript
const search = new SearchQuery({
operator: Operator.And,
conditions: [
{
field: "fullName",
operation: Operation.Equal,
values: ["Dennis Ritchie"],
},
{
field: "created",
// Only two values for Between, NotBetween
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,
},
],
},
],
});
CSharp
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),
// Only two values for Between, NotBetween
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 query = db.Entities.Search(searchQuery).ToList();
}
API
Namespace: SearchQuery
Class: Extensions
Search Methods
Search 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;
- Description: Filters an
IEnumerablecollection based on the providedSearchquery object. - Parameters:
set: The collection to search.query: The search query.pageNumber: (Optional) The page number for paginated results.pageSize: (Optional) The size of each page.
- Returns: Filtered
IEnumerable.
Search 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;
- Description: Filters an
IQueryablecollection based on the providedSearchquery object. - Parameters: Same as above.
- Returns: Filtered
IQueryable.
Type Analysis Methods
InType
public static Type? InType(this Type? valueType, bool isColletion = false);
- Description: Extracts the underlying type, especially for nullable or generic collection types.
IsNull
public static bool IsNull(this Type? valueType);
- Description: Determines if the given type is null.
InNull
public static Type? InNull(this Type? valueType);
- Description: Converts a type to a nullable type if applicable.
IsType
public static Types IsType(this Type type, bool isColletion = false);
- Description: Maps the type to a specific
Typesenum value (e.g.,String,Number,Boolean,Date,Null).
IsCollection
public static bool IsColletion(this Type type);
- Description: Determines if the type represents a collection.
Type Checking Methods
public static bool IsBoolean(this Type? valueType, bool isColletion = false);
public static bool IsNumber(this Type? valueType, bool isColletion = false);
public static bool IsDate(this Type? valueType, bool isColletion = false);
public static bool IsString(this Type? valueType, bool isColletion = false);
- Description: Determines if the type represents a specific data type or a collection.
Namespace: SearchQuery.NewtonsoftJson
Class: Extensions
JSON Search Methods
Convert JSON to Search Query
public static JSearch ToSearch(this string json);
- Description: Converts a JSON string to a
JSearchobject.
Search for IEnumerable
public static IEnumerable<T> Search<T>(this IEnumerable<T> set, string query) where T : class;
public static IEnumerable<T> Search<T>(this IEnumerable<T> set, string query, int pageNumber, int pageSize) where T : class;
- Description: Filters an
IEnumerablecollection using a JSON query string.
Search for IQueryable
public static IQueryable<T> Search<T>(this IQueryable<T> set, string query) where T : class;
public static IQueryable<T> Search<T>(this IQueryable<T> set, string query, int pageNumber, int pageSize) where T : class;
- Description: Filters an
IQueryablecollection using a JSON query string.
Class: JSearch
Attributes
- JsonConverter
[Newtonsoft.Json.JsonConverter(typeof(SearchConverter))]- Description: Indicates that the
JSearchclass uses a custom JSON converter for serialization and deserialization.
- Description: Indicates that the
Methods
ToJson
public string ToJson();
- Description: Serializes the
JSearchobject into a JSON string using Newtonsoft.Json.
FromJson
public static JSearch FromJson(string json);
- Description: Deserializes a JSON string into a
JSearchobject.
Constructor
JSearch()public JSearch() : base()- Description: Initializes a new instance of the
JSearchclass.
- Description: Initializes a new instance of the
Namespace: SearchQuery.SystemTextJson
Class: Extensions
JSON Search Methods
Convert JSON to Search Query
public static JSearch ToSearch(this string json);
- Description: Converts a JSON string to a
JSearchobject.
Search for IEnumerable
public static IEnumerable<T> Search<T>(this IEnumerable<T> set, string query) where T : class;
public static IEnumerable<T> Search<T>(this IEnumerable<T> set, string query, int pageNumber, int pageSize) where T : class;
- Description: Filters an
IEnumerablecollection using a JSON query string.
Search for IQueryable
public static IQueryable<T> Search<T>(this IQueryable<T> set, string query) where T : class;
public static IQueryable<T> Search<T>(this IQueryable<T> set, string query, int pageNumber, int pageSize) where T : class;
- Description: Filters an
IQueryablecollection using a JSON query string.
Enums and Supporting Classes
Enum: Types
public enum Types
{
String,
Number,
Boolean,
Date,
Null
}
Class: JSearch
- Description: Represents a JSON-based search query object.
- Methods:
public static JSearch FromJson(string json);
Namespace: SearchQuery
Class: Search
Properties
Formatpublic Format Format { get; set; }- Description: Specifies the format for interpreting date-time values in search queries.
- Default Value:
Format.ISODateTime
Constructor
Search()public Search() : base()- Description: Initializes a new instance of the
Searchclass with default settings.
- Description: Initializes a new instance of the
Class: JSearch
Attributes
- JsonConverter
[System.Text.Json.Serialization.JsonConverter(typeof(SearchConverter))]- Description: Indicates that the
JSearchclass uses a custom JSON converter for serialization and deserialization.
- Description: Indicates that the
Methods
ToJsonpublic string ToJson();- Description: Serializes the
JSearchobject into a JSON string using System.Text.Json.
- Description: Serializes the
FromJsonpublic static JSearch FromJson(string json);- Description: Deserializes a JSON string into a
JSearchobject.
- Description: Deserializes a JSON string into a
Constructor
JSearch()public JSearch() : base()- Description: Initializes a new instance of the
JSearchclass.
- Description: Initializes a new instance of the
Query Class
Inheritance ISearch Interface
| Property | Type | Default | Description |
|---|---|---|---|
| Operator | Operator | And | And, Or |
| Conditions | Conditions | new Conditions() | Inherit from List with ISearch generic type |
| Format | Format | ISODateTime | ISO Formats, DateOnly Formats, TimeOnly Formats |
Condition Class
Inheritance ISearch Interface
| Property | Type | Default | Description |
|---|---|---|---|
| Field | string | "" | Entity property name |
| Operation | Operation | Operation.Equal | Action operation |
| Values | Values | new Values() | Inherit from List with object generic type |
| Incase | Case | Case.Default | Transform string for Contains, NotContains, StartsWith, NotStartsWith, EndsWith, NotEndsWith operation |
| Format | Format | ISODateTime | ISO Formats, DateOnly Formats, TimeOnly Formats |
Conditions Class
Inheritance Base is generic list
Operation Enum
| Key | Value | String | Date | Number | Boolean | Null |
|---|---|---|---|---|---|---|
| Equal | 0 | By Type | By Type | By Type | By Type | By Type |
| NotEqual | 1 | By Type | By Type | By Type | By Type | By Type |
| LessThan | 2 | Compare | By Type | By Type | Compare | Ignore |
| LessThanOrEqual | 3 | Compare | By Type | By Type | Compare | Ignore |
| GreaterThan | 4 | Compare | By Type | By Type | Compare | Ignore |
| GreaterThanOrEqual | 5 | Compare | By Type | By Type | Compare | Ignore |
| Contains | 6 | By Type | As String | As String | As String | Ignore |
| NotContains | 7 | By Type | As String | As String | As String | Ignore |
| StartsWith | 8 | By Type | As String | As String | As String | Ignore |
| NotStartsWith | 9 | By Type | As String | As String | As String | Ignore |
| EndsWith | 10 | By Type | As String | As String | As String | Ignore |
| NotEndsWith | 11 | By Type | As String | As String | As String | Ignore |
| Between | 12 | Compare | Compare | By Type | Compare | Ignore |
| NotBetween | 13 | Compare | Compare | By Type | Compare | Ignore |
Case Enum
| Key | Value |
|---|---|
| Default | 0 |
| Lower | 1 |
| Upper | 2 |
Operator Enum
| Key | Value |
|---|---|
| And | 0 |
| Or | 1 |
Types Enum
| Key | Value |
|---|---|
| Null | 0 |
| String | 1 |
| Number | 2 |
| Boolean | 3 |
| Date | 4 |
Format Enum
| Key | Value | Format |
|---|---|---|
| DateOnly | 1 | yyyy-MM-dd |
| TimeOnly | 2 | HH:mm:ss |
| ISODateTime | 3 | yyyy-MM-ddTHH:mm:ss |
| ISODateTimeWithMilliseconds | 4 | yyyy-MM-ddTHH:mm:ss.fff |
| ISODateTimeWithOffset | 5 | yyyy-MM-ddTHH:mm:sszzz |
| ISODateTimeUTC | 6 | yyyy-MM-ddTHH:mm:ssZ |
| ISODateTimeWithMillisecondsUTC | 7 | yyyy-MM-ddTHH:mm:ss.fffZ |
| DateDay | 11 | dd |
| DateMonth | 12 | MM |
| DateYear | 13 | yyyy |
| TimeOn | 21 | HH:mm |
| TimeHours | 22 | HH |
| TimeMinutes | 23 | mm |
| TimeSeconds | 24 | ss |
| TimeMilliseconds | 25 | fff |
| TimeFull | 26 | HH:mm:ss.fff |
| Product | Versions 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.