How to create a Lambda expression with Group by and Order By

1

I'm having trouble creating a Lambda sentence with Group by and Order By Together.

How do I group by the Scope and IDScope column, and sort by IDEscope.

Judgment follows.

 public static List<Escopos> EscoposCalCliente(int IDCalCLiente)
        {
            using (entidadesIUS entidades = new entidadesIUS())
            {
                return entidades.Escopos.Where(e => e.CALClientes.Any(cc => cc.IDCALCliente == IDCalCLiente)).
                ToList().
                GroupBy(es => new {.IDEscopo, es.IDEscopo }).
                SelectMany(esc => esc.OrderBy(escp => escp.IDEscopo));
            }
        }
    
asked by anonymous 18.12.2014 / 19:39

1 answer

3

I see no need in your example to use GroupBy and OrderBy . Only OrderBy does all the work.

    public static List<Escopos> EscoposCalCliente(int IDCalCLiente)
    {
        using (entidadesIUS entidades = new entidadesIUS())
        {
            return entidades.Escopos
                .Where(e => e.CALClientes.Any(cc => cc.IDCALCliente == IDCalCLiente))
                .OrderBy(es => es.IDEscopo)
                .ToList();
        }
    }
    
18.12.2014 / 19:47