A Fast and efficient dotnet library to dynamically generate compiled lambda expressions from sql style filters.
DynamicFilter.Sql package can be install via Nuget
dotnet add package DynamicFilter.Sql
The Compile
function takes a generic parameter that is used to determine the entity fields. This could be a user defined class or it could be a Dictionary<string, object>
type.
With a user defined class, the field names within the filter expression have to match the property names defined within the class. This is resolved at compile time.
var myfilter = FilterExpression.Compile<User>("(Age > 10) and (Name like 'Alice%' or Name like 'Bob%')");
//Evaluate a single object
bool match = myFilter(new User {Age = 15, Name="Alice Wonderland"})
//Filter a collection
var names = users.Where(myfilter).Select(u => u.Name);
var dict = new Dictionary<string, object> {
{"Name" , "Alice"},
{"Age" , 12},
};
var filter = FilterExpression.Compile<Dictionary<string, object>>("(Age > 10) and (Name like 'Alice%' or Name like 'Bob%')");
var match = filter(dict); //returns true
- Compile to .NET IL code.
- Support Sql Comparison operations
- =, <, >, <=, >=
- like, not like
- in, not in
- is null, is not null
- Dictionary and User objects
- Dynamically generate code to filter objects in memory
- Filter a stream of data with a multiple criteria
- User Preferences/Filters that could be potentially saved/loaded from a File/Database.