Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Expression Support #20

Open
1 of 8 tasks
enisn opened this issue Dec 22, 2020 · 2 comments
Open
1 of 8 tasks

Select Expression Support #20

enisn opened this issue Dec 22, 2020 · 2 comments
Assignees
Milestone

Comments

@enisn
Copy link
Owner

enisn commented Dec 22, 2020

Summary

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

Declaration

See usage example for better understanding:

  • Entity
public class Book
{
  public string Name { get; set; }

  public int TotalPage { get; set; }

  public DateTime CreateDate { get; set; }

  public virtual ICollection<BookOrder> BookOrders { get; set; }
}
  • FilterDto (As always but inherits SelectorFilterBase)
public class BookFilterDto : SelectorFilterBase<BookDto>
{
  [ToLowerContainsComparison]
  public string Name { get; set; }

  public Range<int> TotalPage { get; set; }

  public Range<DateTime> CreateDate { get; set; }
}
  • Output dto:
public class BookDto
{
  [From("Name")]
  public string Title { get; set; }

  public int TotalPage { get; set; }

  public DateTime CreateDate { get; set; }

  [Count("BookOrders")]
  public int SellCount { get; set; }

  [Sum("BookOrders.Price")]
  public float TotalSoldPrice { get; set; }
}

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());
}
  • Or alternative 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.ApplySelector(filter)  // IQueryable<BookDto>
                            .Where(x => x.TotalSoldPrice > 299.95); // If db provider supports.

    return Ok(query.ToList());
}

Structure

  • FilterBase
    • OrderableFilterBase
      • PaginationFilterBase
        • SelectorFilterBase

TODO List

  • Extension methods for last user usage
  • SelectorFilterBase and SelectorPaginationFilterBase implementation.
  • Attributes
    • Sum
    • Count
    • Min
    • Max
    • Average
@enisn enisn added the feature label Dec 22, 2020
@enisn enisn self-assigned this Dec 22, 2020
@enisn enisn changed the title Select query Select Expression Support Dec 22, 2020
@enisn enisn added this to the v2.7 milestone Dec 22, 2020
@enisn enisn pinned this issue Dec 24, 2020
@enisn
Copy link
Owner Author

enisn commented Dec 25, 2020

@enisn enisn modified the milestones: v2.7, v2.8 Apr 6, 2021
@enisn enisn modified the milestones: v2.8, Backlog Jul 7, 2021
@enisn
Copy link
Owner Author

enisn commented Jan 11, 2022

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.

  • Also, this is a 'Filtering' library, it doesn't aim projection by the way

@enisn enisn unpinned this issue Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant