SmartWhere is a production-ready .NET library that provides intelligent filtering capabilities for IQueryable<T> collections. It transforms complex filtering logic into simple, declarative code using attributes and interfaces, making your data access layer cleaner and more maintainable.
- π― Intelligent Filtering: Automatically generates WHERE clauses from request objects
- π Deep Property Navigation: Support for nested property filtering (e.g.,
Books.Author.Name) - π·οΈ Attribute-Based Configuration: Simple attribute decoration for filter properties
- π§ Type-Safe Operations: Full IntelliSense support and compile-time validation
- β‘ High Performance: Optimized expression tree generation
- π¨ Clean Architecture: Follows SOLID principles and DRY methodology
- π Easy Integration: Single-line integration with existing Entity Framework queries
- π Comprehensive Support: Works with any
IQueryable<T>implementation
Install the SmartWhere NuGet package:
# Package Manager Console
PM> Install-Package SmartWhere
# .NET CLI
dotnet add package SmartWhere
# NuGet Package Manager
Install-Package SmartWhere- Define your search request implementing
IWhereClause:
public class PublisherSearchRequest : IWhereClause
{
[WhereClause]
public int Id { get; set; }
[WhereClause(PropertyName = "Name")]
public string PublisherName { get; set; }
[WhereClause("Book.Name")]
public string BookName { get; set; }
[WhereClause("Books.Author.Name")]
public string AuthorName { get; set; }
}- Use SmartWhere in your queries:
[HttpPost]
public IActionResult GetPublishers(PublisherSearchRequest request)
{
var result = _context.Set<Publisher>()
.Include(x => x.Books)
.ThenInclude(x => x.Author)
.Where(request) // π― SmartWhere magic happens here!
.ToList();
return Ok(result);
}That's it! SmartWhere automatically generates the appropriate WHERE clauses based on your request object.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SmartWhere Library β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π Core Components β
β β’ WhereClauseAttribute β’ IWhereClause Interface β
β β’ Extensions β’ Logical Operators β
β β’ Comparison Operators β’ String Methods β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π§ Extension Methods β
β β’ Where(request) β’ And(request) β
β β’ Or(request) β’ Not(request) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π― Attribute System β
β β’ WhereClause β’ TextualWhereClause β
β β’ ComparativeWhereClause β’ WhereClauseClass β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π WhereClauseAttribute: Base attribute for simple property filtering
- π TextualWhereClauseAttribute: Advanced text search with multiple string methods
- βοΈ ComparativeWhereClauseAttribute: Numeric and date comparison operations
- π·οΈ WhereClauseClassAttribute: Class-level filtering configuration
- π IWhereClause Interface: Contract for filter request objects
- β‘ Extensions: Fluent API for complex filtering operations
public class BookSearchRequest : IWhereClause
{
[TextualWhereClause(StringMethod.Contains, PropertyName = "Title")]
public string Title { get; set; }
[TextualWhereClause(StringMethod.StartsWith, PropertyName = "ISBN")]
public string ISBN { get; set; }
[TextualWhereClause(StringMethod.EndsWith, PropertyName = "Description")]
public string Description { get; set; }
}public class OrderSearchRequest : IWhereClause
{
[ComparativeWhereClause(ComparisonOperator.GreaterThan, PropertyName = "TotalAmount")]
public decimal MinAmount { get; set; }
[ComparativeWhereClause(ComparisonOperator.LessThanOrEqual, PropertyName = "OrderDate")]
public DateTime MaxDate { get; set; }
[ComparativeWhereClause(ComparisonOperator.Between, PropertyName = "Quantity")]
public int QuantityRange { get; set; }
}// Combine multiple filters with logical operators
var result = _context.Orders
.Where(request1)
.And(request2)
.Or(request3)
.Not(request4)
.ToList();public class AdvancedSearchRequest : IWhereClause
{
[WhereClause("Publisher.Country.Name")]
public string CountryName { get; set; }
[WhereClause("Books.Genre.Category")]
public string GenreCategory { get; set; }
[WhereClause("Books.Author.BirthCountry.Region")]
public string AuthorRegion { get; set; }
}- Simple Filter: ~0.1ms overhead per filter
- Complex Nested Filter: ~0.5ms overhead per filter
- Memory Usage: Minimal additional memory footprint
- Compilation: Expression trees generated at runtime for optimal performance
- Use projection for large result sets
- Implement caching for frequently used filters
- Consider database indexing for filtered properties
- Use pagination for large datasets
git clone https://github.com/byerlikaya/SmartWhere.git
cd SmartWhere
dotnet restore
dotnet build
dotnet test# Run all tests
dotnet test
# Run specific test project
dotnet test tests/SmartWhere.Tests/
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"cd sample/Sample.Api
dotnet runBrowse to the API endpoints to see SmartWhere in action.
// In Program.cs or Startup.cs
services.Configure<SmartWhereOptions>(options =>
{
options.DefaultStringMethod = StringMethod.Contains;
options.CaseSensitive = false;
options.MaxNestingLevel = 10;
});[WhereClauseClass(DefaultStringMethod = StringMethod.StartsWith)]
public class CustomSearchRequest : IWhereClause
{
[WhereClause]
public string Name { get; set; }
}| Attribute | Description | Example |
|---|---|---|
WhereClause |
Basic property filtering | [WhereClause] |
TextualWhereClause |
Text search with methods | [TextualWhereClause(StringMethod.Contains)] |
ComparativeWhereClause |
Numeric/date comparisons | [ComparativeWhereClause(ComparisonOperator.GreaterThan)] |
WhereClauseClass |
Class-level configuration | [WhereClauseClass] |
| Method | Description | SQL Equivalent |
|---|---|---|
Contains |
Substring search | LIKE '%value%' |
StartsWith |
Prefix search | LIKE 'value%' |
EndsWith |
Suffix search | LIKE '%value' |
Equals |
Exact match | = 'value' |
| Operator | Description | SQL Equivalent |
|---|---|---|
Equals |
Equal to | = |
NotEquals |
Not equal to | != |
GreaterThan |
Greater than | > |
LessThan |
Less than | < |
GreaterThanOrEqual |
Greater than or equal | >= |
LessThanOrEqual |
Less than or equal | <= |
Between |
Range check | BETWEEN |
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following SOLID principles
- Add comprehensive tests
- Ensure 0 warnings, 0 errors
- Submit a pull request
- Follow SOLID principles
- Maintain DRY methodology
- Write comprehensive tests
- Ensure 0 warnings, 0 errors
- Use meaningful commit messages
- π― Enhanced Performance: Optimized expression tree generation
- π Improved Nested Property Support: Better handling of complex property paths
- π§Ή Code Quality Improvements: SOLID principles implementation
- π Enhanced Documentation: Comprehensive examples and API reference
- β‘ Better Error Handling: Improved validation and error messages
- π Async Support: Async filtering operations
- π Query Analytics: Performance monitoring and insights
- π¨ Custom Operators: User-defined comparison operators
- π Multi-Language Support: Localized error messages
- π Wiki Documentation
- π GitHub Repository
- π Issue Tracker
- π¬ Discussions
- π¦ NuGet Package
This project is licensed under the MIT License - see the LICENSE file for details.
- Entity Framework Team for the excellent
IQueryable<T>foundation - .NET Community for inspiration and feedback
- Contributors who help improve SmartWhere
Built with β€οΈ by BarΔ±Ε Yerlikaya
Made in Turkey πΉπ· | Contact | LinkedIn
β Star this repository if you find SmartWhere helpful! β