Skip to content

byerlikaya/SmartWhere

Repository files navigation

SmartWhere

It intelligently filters a sequence of items in a simple and practical way.

GitHub Workflow Status (with event) SmartWhere Nuget SmartWhere Nuget

SmartWhere is a method that aims to make the Queryable.Where method smarter and is based on the foundations of .NET.

I would be very happy if you could star ⭐ the project.

Quick Start

The usage of SmartWhere is quite simple.

  1. Install SmartWhere NuGet package from here.
PM> Install-Package SmartWhere
  1. You need to define our Request object for SmartWhere and sign it with the IWhereClause interface.
 public class PublisherSearchRequest : IWhereClause
  1. We mark the properties to be included in the filter with the WhereClause Attribute.
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. And we filter smartly. That's it.
 [HttpPost]
 public IActionResult GetPublishers(PublisherSearchRequest request)
 {
     var result = _context.Set<Publisher>()
         .Include(x => x.Books)
         .ThenInclude(x => x.Author)
         .Where(request)
         .ToList();

     return Ok(result);
 }

Be sure to check out the Wiki page for more details. ⭐