Summary
I was working with Pagination, and I found the way it was currently implemented to be restricting. I found (1) bug, and (1) major improvement that could be made.
For my own projects, this is a reason why I would not use this library (no offense). Many people need pagination to return:
Standard Pagination Response Object:
https://stackoverflow.com/questions/12168624/pagination-response-payload-from-a-restful-api
{
"_metadata":
{
"page": 5,
"per_page": 20,
"page_count": 20,
"total_count": 521,
"Links": [
{"self": "/products?page=5&per_page=20"},
{"first": "/products?page=0&per_page=20"},
{"previous": "/products?page=4&per_page=20"},
{"next": "/products?page=6&per_page=20"},
{"last": "/products?page=26&per_page=20"},
]
},
"records": [
{
"id": 1,
"name": "Widget #1",
"uri": "/products/1"
},
{
"id": 2,
"name": "Widget #2",
"uri": "/products/2"
},
{
"id": 3,
"name": "Widget #3",
"uri": "/products/3"
}
]
}
Something like this^^
The key is to get this back as a JSON response object:
{
"page": 5,
"per_page": 20,
"page_count": 20,
"total_count": 521,
"Links": [
{"self": "/products?page=5&per_page=20"},
{"first": "/products?page=0&per_page=20"},
{"previous": "/products?page=4&per_page=20"},
{"next": "/products?page=6&per_page=20"},
{"last": "/products?page=26&per_page=20"},
]
}
or at the minimum return this as a JSON response object:
{
"page": 5,
"per_page": 20,
"page_count": 20,
"total_count": 521,
}
Current Pagination Bugs
- You use the library AutoFilterer to implement filtering and pagination
- When you work with filtering and pagination, you eliminate any Pagination Object to be returned. See Code below
public List<TEntity> GetMultiple<TEntity, TFilter>(EfTrackingOptions asNoTracking, TFilter filter)
where TEntity : class
where TFilter : FilterBase
{
return this.FindQueryable<TEntity>(asNoTracking)
.ApplyFilter(filter)
.ToList();
}
What is currently implemented (This is the bug):
- There is an DBO Entity, just something in the database
- You apply the pagination style filtering to it
- Then you return the DBO Entity instead of the Pagination Response Object
- This means if the user has some pagination properties such as Total Pages, Current Page, Total Results, etc... These will not be returned to the user. Only the DBO Entity will be returned.
Proposed Changes
I propose (2) things:
- Remove the filtering and pagination from the current library, create a new extension library called
EasyRepository.EfCore.AutoFilterer
-- This will allow us to implement new filter implementation using Gridify, Sieve and others, instead of currently we are 'married' to AutoFilterer
This is the improvement I mentioned in the beginning of my post.
- On Filtered and Paginated Methods, return the
TFilter
object instead of the TEntity
Object. This will be a 'breaking change' as it involves changing what currently implemented methods return.
- Perhaps, to avoid the breaking change, instead we add a suffix of
Paged
or Filtered
to the method. I prefer the suffix of Paged
as mostly all Filtered
use-cases for UI's will also be Paged
.
Closing Statement
To be honest, I need these methods in my own implementation, so I will get started on this. If you reject this proposal I 100% understand, and I will keep the code to myself.
If you think this is helpful and useful, I will add my code and create a pull-request so that our branches can be 'in-sync'.
What are your thoughts? Please make any changes or suggestions as you see fit.