Sort 2 columns at a time - Asp Mvc + Fluentnhibernate

Asked

Viewed 116 times

6

Good morning!

I would like to know how to order two columns at once in a query so that in my case, 1 in descending order of date but in alphabetical order.

        public IList<Analise> ListaTodosOrdenado()
    {
        using (ISession _session = FHibernateHelper.AbreSession())
        {

            var analises = _session.QueryOver<Analise>()                      
                                 .JoinQueryOver(p => p.MateriaPrima)
                                 .TransformUsing(Transformers.DistinctRootEntity)
                                 .List();

            var a = analises.OrderByDescending(d => d.DataCadastro).OrderBy(n=>n.MateriaPrima.Nome);


                return (analises);
        }
    }

In these lines of code, it first orders by date, but the second ordering overrides the first.

  • http://stackoverflow.com/a/4658205/2221388 See if this can help you

  • Thanks Paulo, it worked!!

1 answer

3

What you should use is the function ThenBy as in the example

MyList
.OrderByDescending(p => p.ToDate)
.ThenByDescending(p => p.Number)
.ThenByDescending(p => p.RunDate)
.FirstOrDefault();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.