enisn / AutoFilterer

AutoFilterer is a mini filtering framework library for dotnet. The main purpose of the library is to generate LINQ expressions for Entities over DTOs automatically. The first aim is to be compatible with Open API 3.0 Specifications
MIT License
458 stars 37 forks source link

Select Expression Support #20

Open enisn opened 3 years ago

enisn commented 3 years ago

Summary

This feature aims to generate an expression for .Select() Linq method.

Declaration

See usage example for better understanding:

Usage

As default, SelectorFilterBase should override ApplyFilter() method, so calling ApplyFilter method will work.

[HttpGet]
public IActionResult GetBooks([FromQuery] BookFilterDto filter)
{
    var query = db.Books.ApplyFilter(filter);  // IQueryable<BookDto>
    return Ok(query.ToList());
}

As default, SelectorFilterBase should override ApplyFilter() method, so calling ApplyFilter method will work.

[HttpGet]
public IActionResult GetBooks([FromQuery] BookFilterDto filter)
{
    var query = db.Books.ApplySelector(filter)  // IQueryable<BookDto>
                            .Where(x => x.TotalSoldPrice > 299.95); // If db provider supports.

    return Ok(query.ToList());
}

Structure

TODO List

enisn commented 3 years ago

This might be useful: https://stackoverflow.com/questions/12701737/expression-to-create-an-instance-with-object-initializer/12705338#12705338

enisn commented 2 years ago

Dynamic Select is not compatible with Open API 3.0 standards. This is the main purpose of AutoFilterer. Only static select support can be provided.