Adding Filtering, Sorting And Pagination To a REST API | .NET 7

Adding Filtering, Sorting And Pagination To a REST API | .NET 7

Milan Jovanović

1 год назад

52,169 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

JAYA Kumar
JAYA Kumar - 27.08.2023 16:59

Source code needed

Ответить
Mahmoud AbdEl-Moughiss
Mahmoud AbdEl-Moughiss - 26.08.2023 11:18

thans alot, this was very useful .🙏🙏

Ответить
Paweł O
Paweł O - 25.08.2023 11:56

Why you didn’t use graphql with EF Core ?

Ответить
Jesús Araujo
Jesús Araujo - 18.08.2023 22:50

With Dapper?

Ответить
phương trần
phương trần - 28.07.2023 07:51

Hi Milan, tks for the video. It would be great if you could make a video on the Expression that you created? I could not wrap my head around that.😂

Ответить
Cristhian Julian Cubides
Cristhian Julian Cubides - 24.07.2023 00:00

I have a question, you are getting all the products with context.Products, if I have 5000 items it gets them all and then you are applying the filtering. Therefore the filter would not make sense because the objects are being loaded into memory and then the paging is applied.
I have a doubt, thank you

Ответить
Mike
Mike - 05.07.2023 22:41

Sorting input can be a bit better using enum string.

Ответить
Nghia Nguyen
Nghia Nguyen - 03.07.2023 06:56

with OData, you dont need to do all implementation by youself.

Ответить
Sajith Sageer
Sajith Sageer - 02.07.2023 23:00

Great video as usual. Any chance of an Odata tutorial?

Ответить
Karthik
Karthik - 02.07.2023 19:11

Thanks for this awesome video.I was searching from long time 😊.

Ответить
Renato Martins
Renato Martins - 30.06.2023 21:07

Could you show us how to implement the sorting if we are using generic classes and we don't know the class attributes before runtime?

Ответить
Don Rodriguez
Don Rodriguez - 29.06.2023 04:02

Your videos are SO good! Thank you for teaching me so much!

Ответить
Jamal Albatta
Jamal Albatta - 29.06.2023 02:26

I loved the Expression with switch to cover the which column to sort by, in my project I have the same amount of search choices I want to cover, so I'm using if else statements, can you please show case or at least right here as a respond an Expression with switch that is used in Where() instead of OrderBy(). I tried it but I'm messing something and i can't get it to work. Thanks a lot for the video, it helped a lot

Ответить
Ramy Tawfik
Ramy Tawfik - 25.06.2023 12:10

Excellent as usual Milan 👌

Ответить
abhinav upreti
abhinav upreti - 24.06.2023 10:07

How do you rate Biarity Sieve for Sorting , Filtering and Pagination? although it has some challenges for VO or complex types

Ответить
Zakaria Smahi
Zakaria Smahi - 24.06.2023 02:00

Thanks for sharing this insightful, in all my api projects i use rye same logic for paging, filtering and sorting. For the pagination i return an object that contains items page number and page size as you did, however instead of returning a boolean HasNextPage or HasPreviousPage, i return string which are url for the previous and next pages already prepared (when i'm one the first page, previous page is null and if i'm in the last page next page is gonna be null )so in case one of clients of my api is working on a batch for frtching data url are already prepared by the api 😃

Thanks for sharing i really like your helpful content

Ответить
tech pc
tech pc - 23.06.2023 20:21

Ответить
kdakan
kdakan - 23.06.2023 10:52

Too much coding to deliver such a simple standard feature. I have a library that does this and much more without any coding.

Ответить
Rafael Gonzalez
Rafael Gonzalez - 22.06.2023 04:13

I had to create something similar but the backend DB was Mongo so I had to use projection, and for the search I used reflection to get the Data Annotation for the BsonElement name and type, the documents had over 150 fields ... It would be nice to add reflection to this tutorial to avoid hard coding the name of the properties, maybe using JsonProperty annotation??? Thanks for the great tutorial

Ответить
Reino Boonstra
Reino Boonstra - 22.06.2023 02:43

Thank you, very helpful. Nice clean coding as well 👍

Ответить
Christian Guitar Covers
Christian Guitar Covers - 21.06.2023 19:16

Milan, this was a very useful video tutorial. thx a lot

Ответить
GeekDriven
GeekDriven - 21.06.2023 18:32

Any thoughts on creating a tutorial for Cursor Pagination or any other types along with explaining the benefits of the same? As always great videos. 😇

Ответить
Trav B
Trav B - 21.06.2023 17:46

How would you do dynamic select/projection?

Ответить
Dave Anderson
Dave Anderson - 21.06.2023 10:54

A few years ago I used a library for parsing OData query options called Moon.OData. I could send an OData query and the program translated it into a normal t-sql. Very simple and safe for both user and developer.
I believe there are more such libraries nowadays. Would definitely recommend that to anyone.

Ответить
Grzegorz Fedoryka
Grzegorz Fedoryka - 21.06.2023 10:37

You could do sorting using dynamic linq
public static IQueryable<Tsource> SetOrdering<Tsource>(this IQueryable<Tsource> query,
string orderColumn, string orderingDirection)
{
if (string.IsNullOrEmpty(orderColumn))
{
return query;
}
return query.OrderBy($"{orderColumn.Trim()} {orderingDirection.Trim().ToLower()}");
}
Ofc column and sort order would be validated in validation step

Ответить
Suresh Kumar
Suresh Kumar - 21.06.2023 08:16

I use a nuget package called sieve to does this .

Ответить
Gustavo Lopes
Gustavo Lopes - 21.06.2023 01:39

Waiting for the Dapper version too! Great video.

Ответить
Can Ozdemir
Can Ozdemir - 21.06.2023 00:27

Thank you for the quality content I have a question. For sorting and searching why didnt you use reflection to search or sort in every column. Also if you add new fields you dont need to add new contains to the where part.

Ответить
Bob Archer
Bob Archer - 20.06.2023 23:46

I highly suggest you determine a maximum page size and use that instead of what the client is requesting if their pagesize exceeds your maximum. :)

Also, I think I like returning the pagination information in headers, rather than in the response payload.

Ответить
Fatih Yücel ŞEN
Fatih Yücel ŞEN - 20.06.2023 21:52

We want the Dapper version too.

Ответить
RafiXWPT
RafiXWPT - 20.06.2023 21:39

Actually what you did there is very bad. The much better solution in to make thing more generic by create more interfaces and base query handlers. Also, way you doing sorting is ugly. You can just use reflection and make it work with whatever object you like without any problem. I created such generic mechsnism in my project using cqrs and efcore and developers who are using it loves that you can add new lists in just minute by inheriring some base generic classess

Ответить
Jose Antonio Teran Suarez
Jose Antonio Teran Suarez - 20.06.2023 21:00

Great video, but I have a question: is it possible to reference the DBContext from the application layer with a clean architecture?

Ответить
TamerAli
TamerAli - 20.06.2023 20:41

Hi Milan, thank for the video.
are you going to refactor the sorting method to be extension method and generic?
var list =await context
.Users
.OrderDescendingByField(nameof(User.Name)) // OrderByField for asc
.ToListAsync();

Ответить
Crazyfox55
Crazyfox55 - 20.06.2023 20:17

Does the select hurt performance of the take, skip, or count async? Calling ToListAsync is when the queryable is actually executed but how does it know to reorder the operations in a performant way?

Ответить
Adeni
Adeni - 20.06.2023 18:33

Have you already done a full tutorial on your channel? I like your teaching style! I wish there is a full tutorial or even a course

Ответить
Rodrigo Chapeta
Rodrigo Chapeta - 20.06.2023 18:07

I was expecting something more generic like Sieve for automatic pagination sorting and filtering.
Or OData or graph

Ответить
Cristhian Cuenca
Cristhian Cuenca - 20.06.2023 17:57

Excellent video! Really helpful! Thanks for sharing! by the way, can you explain in a short video format the record and sealed modifiers from your perspective and it's importance the documentation not consider optimization benefits. Thanks

Ответить
Emir Salihović
Emir Salihović - 20.06.2023 17:35

Bravo doktore 🤝

Ответить
Bishal
Bishal - 20.06.2023 16:53

Why not GrapaQL?

Ответить
G AKSHAY
G AKSHAY - 20.06.2023 16:28

Thank you for covering those topics which are helpful in handling performance issues.
On filtering, if the table has multiple columns, then the number of parameters may grow. is there a generic way to easily achieve it.
On pagination, if the result fits in 5 pages, the client should call the API for 5 times. So, the end query will be executed 5 times by considering the page number. will it not affect the sql performance

Ответить
Josimar Pereira Santana
Josimar Pereira Santana - 20.06.2023 16:09

Is there a standard way for adding specific/complex filters? For example, filtering by a date interval or a price range. Creating this in a generic way to be reused in several endpoints

Ответить
Samuel Maharjan
Samuel Maharjan - 20.06.2023 15:30

It seems like a good tutorial but I am having difficulty following your architecture and stuff about record and sku. Are there any prior videos that I need to watch? This has been happening to me for quite a few videos so any help in that will be very appreciated.

Ответить
toragodzen
toragodzen - 20.06.2023 15:28

Could you make implicit operator for Sku, so we will remove type casting and just use Sku where string is expected?

Ответить
BOBx5
BOBx5 - 20.06.2023 15:13

Ahhhh .... you are amazing

Ответить
Stefan Djokic
Stefan Djokic - 20.06.2023 15:05

Great, in-detail tutorial!

Ответить
Azra Iqbal
Azra Iqbal - 20.06.2023 14:33

Really helpful 😊

Which machine are you using for editing and recoding? Specs

Thanks 👍

Ответить
tech pc
tech pc - 20.06.2023 14:04

Ответить