Click here to Skip to main content
15,887,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have three tier arhitecture in web app (asp.net)

should sort and pagination be in presentation layer or business logic?

C#
//Search.aspx.cs
public void SearchProjects(int recordCount)
{
    var data = DAL.GetData();

    var filtered = data.OrderBy(x => x.Key).Take(recordCount);

    //todo
}

or
C#
//Search.aspx.cs
public void SearchProjects(int recordCount, object sortType)
{
    var data = DAL.GetData(recordCount, sortType);

    //todo
}
Posted
Comments
Richard Deeming 10-Nov-15 10:20am    
Does the GetData method return an implementation of IQueryable<>?

If not, doing the sorting and paging in the calling code will be extremely inefficient.

1 solution

"It depends". What does GetData return? If it returns an IQuereable or IEnumerable such that the query hasn't yet been issues by the time it gets to the presentation layer then you could do the paging\sorting at the presentation layer.

If GetData actually retrieves all data and returns it as an in-memory datastore like DataSet, List<t> etc then you shouldn't page\sort in the presentation layer.

Getting back to the first scenario...if GetData returns IQuereable then you could consider that bad design as you are tightly-coupling your presentation layer to the data layer as your presentation code can only work with datastores that support lazy-loading via IQuereable. It means that your presentation layer will often need knowledge of the data store to do its work. If GetData reads all the rows into an in-memory data store and returns that then you don't have those issues, however your paging\sorting will need to be done at the data layer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900