SkillAgentSearch skills...

SmartWhere

๐Ÿš€ SmartWhere - Intelligent .NET filtering library that transforms complex filtering logic into simple, declarative code using attributes and interfaces. Perfect for Entity Framework and IQueryable<T> collections.

Install / Use

/learn @byerlikaya/SmartWhere
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

๐Ÿš€ SmartWhere - Intelligent .NET Filtering Library

GitHub Workflow Status (with event) SmartWhere Nuget SmartWhere Nuget .NET License Code Quality

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.

โœจ Key Highlights

  • ๐ŸŽฏ 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

๐Ÿš€ Quick Start

Installation

Install the SmartWhere NuGet package:

# Package Manager Console
PM> Install-Package SmartWhere

# .NET CLI
dotnet add package SmartWhere

# NuGet Package Manager
Install-Package SmartWhere

Basic Usage

  1. 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; }
}
  1. 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.

๐Ÿ—๏ธ Architecture & Components

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    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             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Components

  • ๐Ÿ“‹ 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

๐ŸŽจ Advanced Usage Examples

Text Search with Multiple Methods

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; }
}

Numeric and Date Comparisons

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; }
}

Complex Logical Operations

// Combine multiple filters with logical operators
var result = _context.Orders
    .Where(request1)
    .And(request2)
    .Or(request3)
    .Not(request4)
    .ToList();

Nested Property Filtering

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; }
}

๐Ÿ“Š Performance & Benchmarks

Performance Metrics

  • 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

Scaling Tips

  • Use projection for large result sets
  • Implement caching for frequently used filters
  • Consider database indexing for filtered properties
  • Use pagination for large datasets

๐Ÿ› ๏ธ Development & Testing

Building from Source

git clone https://github.com/byerlikaya/SmartWhere.git
cd SmartWhere
dotnet restore
dotnet build
dotnet test

Running Tests

# Run all tests
dotnet test

# Run specific test project
dotnet test tests/SmartWhere.Tests/

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

Sample API

cd sample/Sample.Api
dotnet run

Browse to the API endpoints to see SmartWhere in action.

๐Ÿ”ง Configuration & Customization

Global Configuration

// In Program.cs or Startup.cs
services.Configure<SmartWhereOptions>(options =>
{
    options.DefaultStringMethod = StringMethod.Contains;
    options.CaseSensitive = false;
    options.MaxNestingLevel = 10;
});

Custom Attribute Usage

[WhereClauseClass(DefaultStringMethod = StringMethod.StartsWith)]
public class CustomSearchRequest : IWhereClause
{
    [WhereClause]
    public string Name { get; set; }
}

๐Ÿ“š API Reference

Core Attributes

| 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] |

String Methods

| Method | Description | SQL Equivalent | |--------|-------------|----------------| | Contains | Substring search | LIKE '%value%' | | StartsWith | Prefix search | LIKE 'value%' | | EndsWith | Suffix search | LIKE '%value' | | Equals | Exact match | = 'value' |

Comparison Operators

| 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 |

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes following SOLID principles
  4. Add comprehensive tests
  5. Ensure 0 warnings, 0 errors
  6. Submit a pull request

Code Quality Standards

  • Follow SOLID principles
  • Maintain DRY methodology
  • Write comprehensive tests
  • Ensure 0 warnings, 0 errors
  • Use meaningful commit messages

๐Ÿ†• What's New

Latest Release (v2.2.2.1)

  • ๐ŸŽฏ 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

Upcoming Features

  • ๐Ÿ”„ Async Support: Async filtering operations
  • ๐Ÿ“Š Query Analytics: Performance monitoring and insights
  • ๐ŸŽจ Custom Operators: User-defined comparison operators
  • ๐ŸŒ Multi-Language Support: Localized error messages

๐Ÿ“š Resources

Related Skills

View on GitHub
GitHub Stars20
CategoryData
Updated7mo ago
Forks2

Languages

C#

Security Score

87/100

Audited on Aug 26, 2025

No findings