Filter.DynamicFilter
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Filter.DynamicFilter --version 1.0.0
NuGet\Install-Package Filter.DynamicFilter -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="Filter.DynamicFilter" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Filter.DynamicFilter --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Filter.DynamicFilter, 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 Filter.DynamicFilter as a Cake Addin #addin nuget:?package=Filter.DynamicFilter&version=1.0.0 // Install Filter.DynamicFilter as a Cake Tool #tool nuget:?package=Filter.DynamicFilter&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Dynamic Filter
A package which provides some generic methods for applying filter dynamically along with linq queries.
Features
- Apply dynamic filter to database linq queries & other list
- Apply dynamic sort to database linq queries & other list
Installation
Using dotnet cli
dotnet add package DynamicFilter;
Usage
Add using
using System.Linq.DynamicFilter;
Apply filter on IAsyncEnumerable
List<User> users = await dbContext.User.AsAsyncEnumerable().ApplyFilter(filter).ToListAsync();
Apply filter on IEnumerable
var filteredList = users.ApplyFilter(filter).ToList();
Building filters
Example filter DTO
{
"filter":{
"condition":"Or",
"filters":[
{
"property":"Name",
"operator":"Contains",
"value":"t2"
},
{
"property":"Employees",
"operator":"Any",
"anyFilter":{
"condition":"And",
"filters":[
{
"property":"FirstName",
"operator":"Contains",
"value":"m",
"caseSensitive": true
},
{
"property":"LastName",
"operator":"Contains",
"value":"i"
}
]
}
}
]
},
"orderBy":[
{
"property":"Id",
"ascending":false
}
],
"skip": 1,
"take": 10
}
condition
: Condition by which its child filters are combined. Supported conditions - "And", "Or"filters
: It should be non-empty, if condition is set.property
: Property name of the entityoperator
: Operator name that can be applied on the specified property of the entity. Supported operators - "Equal","NotEqual","GreaterThan","LessThan","GreaterThanOrEqual","LessThanOrEqual","Between","BetweenInclusive","In","NotIn","Contains","NotContains","Any"value
: It is a dynamic property. It can be null, if operator is "Any". Example values - "Hello", 123, true, "2022-04-06", [1,4,6,3], ["This","is","a","sample"], ["2022-04-06","2000-01-10"]caseSensitive
: Its default value is false. It decides whether case should be considered or notAnyFilter
: Filter that should be applied inside "Any" method. It is applicable only if the operator is "Any"orderBy
: A list of property names by which the list should be sorted. Sorting will depend on the order of properties specified in this list. It is optionalascending
: Default value is true.skip
: number of records to be skipped from the ordered list. It is optionaltake
: number of records to be taken from the list. It is optional
Example Entities :
public class Employee
{
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime DateOfJoining { get; set; }
public bool IsPermanent { get; set; }
public virtual Department Department { get; set; }
}
public class Department
{
public long Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public virtual List<Employee> Employees { get; set; }
}
Sample filters for Employee
{
"filter":{
"property":"FirstName",
"operator":"Equal",
"value":"Marcos"
}
}
{
"filter":{
"property":"Age",
"operator":"Equal",
"value":30
}
}
{
"filter":{
"property":"FirstName",
"operator":"In",
"value":[
"Marcos",
"John"
]
},
"orderBy":[
{
"property":"FirstName"
}
]
}
{
"filter":{
"condition":"Or",
"filters":[
{
"property":"Id",
"operator":"Equal",
"value":2
},
{
"property":"Id",
"operator":"Equal",
"value":1
}
]
},
"orderBy":[
{
"property":"FirstName",
"ascending":true
}
],
"skip":0,
"take":10
}
{
"filter":{
"property":"Department.Name",
"operator":"Contains",
"value":"1",
"caseSensitive":true
},
"orderBy":[
{
"property":"FirstName",
"ascending":true
}
],
"skip":0,
"take":10
}
Sample filters for Department
{
"filter":{
"property":"Employees",
"operator":"Any"
},
"orderBy":[
{
"property":"Id"
}
]
}
{
"filter":{
"property":"Employees",
"operator":"Any",
"anyFilter":{
"property":"FirstName",
"operator":"Contains",
"type":"String",
"value":"a"
}
},
"orderBy":[
{
"property":"Id"
}
]
}
{
"filter":{
"property":"Employees",
"operator":"Any",
"anyFilter":{
"condition":"And",
"filters":[
{
"property":"FirstName",
"operator":"Contains",
"value":"M",
"caseSensitive":true
},
{
"property":"LastName",
"operator":"Contains",
"value":"i"
}
]
}
}
}
{
"filter":{
"condition":"Or",
"filters":[
{
"property":"Employees",
"operator":"Any",
"anyFilter":{
"condition":"And",
"filters":[
{
"property":"FirstName",
"operator":"Contains",
"value":"m"
},
{
"property":"LastName",
"operator":"Contains",
"value":"i"
}
]
}
},
{
"property":"Name",
"operator":"Contains",
"value":"t2"
}
]
},
"orderBy":[
{
"property":"Id",
"ascending":false
}
]
}
License
MIT
Free Package
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Newtonsoft.Json (>= 13.0.2)
- System.Interactive.Async (>= 6.0.1)
- System.Text.Json (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
ApplyFilter method on IAsyncEnumberable and IEnumerable to apply filter dynamically