Question

I am using the nice s#arp repositories and the paging extension method plus sorting like this:

public ViewResult Index(int? page, GridSortOptions sort) 
        {
            ViewData["sort"] = sort;

            if (!string.IsNullOrEmpty(sort.Column))
            {
                return View(this.LabService.GetAllLabs().OrderBy(sort.Column, sort.Direction).AsPagination(page ?? 1, 10));
            }

...

My first question is:

(1) Is it correct that the sorting has to be done before the paging and that all this uses lazy loading (i.e. internally uses TOP n or something in the actual SQL)?

One of the short comings of the current mvc contrib grid implementation is that it does not allow sorting for customised columns (e.g. combined column values) like this:

String.Format("{0} {1}", lab.Proposer.LastName, lab.Proposer.FirstName)

(used in the view)

I tried to avoid view models in my fairly simple s#arp solution but perhaps I could do with a view model in this case to allow the sorting by custom columns.

I have used automapper to map domain models to view models and vice versa in the past. However, I have one issue with this solution. Does this still work using lazy loading?

In other words does automapper not have to map ALL domain objects to the view objects first before it can do sorting and paging resulting in decreased performance?

I hope this makes sense and you understand what I am getting at. Thanks.

Best wishes,

Christian

Was it helpful?

Solution

  1. Yes sorting and querying ( where something = bla bla) has to be done before paging, actually you have to care about this only if you write sql, otherwise if you use hibernate or linq2sql or something similar than you don't

  2. all automapper is doing is taking the values from one object and putting it into another object (there is some data conversion involved, configuration and all that stuff), unless you write some stuff in a custom valueresolver where you can basically write anything and after you can use this valueresolver for some specific property

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top