Where does paging, sorting, etc go in repository pattern?

前端 未结 5 1768
无人及你
无人及你 2021-02-01 07:04

Where do we put the logic for paging and sorting data in an asp.net repository pattern project?

Should it go in the service layer or put it in the controller and have th

5条回答
  •  花落未央
    2021-02-01 07:18

    • Sorting: should be done in the repository for large result sets; may be done inside the controller for small collections (i.e. without paging).
    • Paging: IMO the repository should expose a way of returning collection slices (which is not exactly the same as paging). Meaning, there should be a way of asking the repository to return a query, starting at the index z and for the next y items. Then everything related to the particular page size (or page index) should be kept inside the controller. That way you can optimize data retrieval, but without coupling your model to a particular presentation requirement.

提交回复
热议问题