Big switch statement for sorting a table I have a webpage with a table.  The table, with 10 columns, can be sorted by each column ascending or descending.

At this moment I control order by big switch:

Func&lt;IQueryable&lt;DeviceUsage&gt;, IOrderedQueryable&lt;DeviceUsage&gt;&gt; orderBy;
        IOrderedEnumerable&lt;DeviceUsage&gt; info;
        switch (sortOrder)
        {
            case "user":
                ViewBag.sortableBy = sortOrder;
                info = unitOfWork.deviceUsageRepository.Get(where, null, null, d =&gt; d.DeviceInstance, d =&gt; d.Storage, d =&gt; d.User).OrderBy(s =&gt; s.User.FullName);
                ViewBag.Desc = true;
                return PartialView(info.ToPagedList(pageNumber, 15));
            case "userDesc":
                ViewBag.sortableBy = sortOrder;
                info = unitOfWork.deviceUsageRepository.Get(where, null, null, d =&gt; d.DeviceInstance, d =&gt; d.Storage, d =&gt; d.User).OrderByDescending(s =&gt; s.User.FullName);
                ViewBag.Desc = true;
                return PartialView(info.ToPagedList(pageNumber, 15));
            case "manufacturer":
                ViewBag.sortableBy = sortOrder;
                orderBy = q =&gt; q.OrderBy(o =&gt; o.DeviceInstance.Device.Manufacturer1.Name);
                break;
            case "manufacturerDesc":
                ViewBag.sortableBy = sortOrder;
                orderBy = q =&gt; q.OrderByDescending(o =&gt; o.DeviceInstance.Device.Manufacturer1.Name);
                break;
            .
            .
            .
            default:
                ViewBag.sortableBy="";
                orderBy=q =&gt; q.OrderBy(o =&gt; o.DeviceInstance.Device.CatalogNo);
                break;
        }


This code works but looks not nice.  I think it's the longest switch I ever wrote.
Can it be someway upgraded or leave it as it is?

Explanation why there is difference in logic:

As you can see in user I'm sorting by Fullname which isn't in db ( its created locally in DAL from FirstName &amp; LastName).  @Nick's approach is ok BUT adding a new Desc variable is a bit problematic because there is only the possibility to sort by ONE row at a time. So I would need to store it somewhere in the last sorting order.
As a quick improvement you should move the line ViewBag.sortableBy... out of your case statement and only set it in the default.

Secondly, I'm noticing there seem to be two different kinds of logic going on here: whether somebody's a user or a manager, etc. or whether the order is ascending or descending. It may be a lot easier to do something like this:

    Func&lt;IQueryable&lt;DeviceUsage&gt;, IOrderedQueryable&lt;DeviceUsage&gt;&gt; orderBy;
    IOrderedEnumerable&lt;DeviceUsage&gt; info;
    ViewBag.sortableBy = ascending? sortField : sortField + "desc";

    switch (sortField)
    {
        case "user":

            var deviceUsage = unitOfWork.deviceUsageRepository.Get(where, null, null, d =&gt; d.DeviceInstance, d =&gt; d.Storage, d =&gt; d.User);
            var orderFunction = s =&gt; s.User.FullName;
            ViewBag.Desc = true;
            info = ascending? deviceUsage.OrderBy(orderFunction); : deviceUsage.OrderByDescending(orderFunction);
            return PartialView(info.ToPagedList(pageNumber, 15));
        case "manufacturer":
            var orderFunction = o =&gt; o.DeviceInstance.Device.Manufacturer1.Name;
            orderBy = ascending? q =&gt; q.OrderBy(orderFunction) : q =&gt; q.OrderByDescending(orderFunction)
            break;
        .
        .
        .
        default:
            ViewBag.sortableBy="";
            orderBy=q =&gt; q.OrderBy(o =&gt; o.DeviceInstance.Device.CatalogNo);
            break;
    }


This code obviously requires you to split out whether an order is ascending or not beforehand. This can be done with string manipulation if necessary, but there is probably an easier way using code you haven't shown us.