SmartWhere
SmartWhere copied to clipboard
It intelligently filters a sequence of items in a simple and practical way.
SmartWhere
It intelligently filters a sequence of items in a simple and practical way.
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.
- Install
SmartWhereNuGet package from here.
PM> Install-Package SmartWhere
- You need to define our Request object for SmartWhere and sign it with the
IWhereClauseinterface.
public class PublisherSearchRequest : IWhereClause
- We mark the properties to be included in the filter with the
WhereClauseAttribute.
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; }
}
- 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. ⭐