SmartWhere 2.2.3

dotnet add package SmartWhere --version 2.2.3
                    
NuGet\Install-Package SmartWhere -Version 2.2.3
                    
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="SmartWhere" Version="2.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartWhere" Version="2.2.3" />
                    
Directory.Packages.props
<PackageReference Include="SmartWhere" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SmartWhere --version 2.2.3
                    
#r "nuget: SmartWhere, 2.2.3"
                    
#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.
#:package SmartWhere@2.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SmartWhere&version=2.2.3
                    
Install as a Cake Addin
#tool nuget:?package=SmartWhere&version=2.2.3
                    
Install as a Cake Tool

πŸš€ 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

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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! ⭐

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SmartWhere:

Package Downloads
EntityGuardian

In your projects developed with EntityFramework, it keeps track of all the changes that take place in your database and records them wherever you want.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.3 124 8/21/2025
2.2.2.1 306 4/8/2025
2.2.2 814 7/10/2024
2.2.1 335 5/16/2024
2.2.0.3 176 4/14/2024
2.2.0.2 682 2/27/2024
2.2.0.1 346 1/22/2024
2.2.0 370 12/2/2023
2.1.1.2 618 10/23/2023
2.1.1.1 181 10/23/2023
2.1.1 220 10/5/2023
2.1.0 171 9/25/2023
2.0.3 185 9/21/2023
2.0.2 179 9/21/2023
2.0.1 182 9/20/2023
2.0.0 227 9/20/2023
1.0.3 173 9/15/2023
1.0.2.1 256 9/11/2023
1.0.2 248 9/11/2023
1.0.1 283 9/11/2023 1.0.1 is deprecated because it is no longer maintained and has critical bugs.
1.0.0 260 9/8/2023 1.0.0 is deprecated because it is no longer maintained and has critical bugs.