Sort 2 columns at once - Asp Mvc + FluentNhibernate

6

Good morning!

I would like to know how to sort two columns at a time in a query so that it is, in my case, 1st 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, the 1st order by date, but the second ordering overlaps the 1st.

    
asked by anonymous 11.10.2016 / 17:23

1 answer

3

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

MyList
.OrderByDescending(p => p.ToDate)
.ThenByDescending(p => p.Number)
.ThenByDescending(p => p.RunDate)
.FirstOrDefault();
    
11.10.2016 / 20:56