-
Notifications
You must be signed in to change notification settings - Fork 2
1. Usage
Barış Yerlikaya edited this page Sep 20, 2023
·
2 revisions
- Install
SmartWhere
NuGet package from here.
PM> Install-Package SmartWhere
- You need to define our Request object for SmartWhere and sign it with the
IWhereClause
interface.
public class PublisherSearchRequest : IWhereClause
- 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; }
}
- 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);
}