How do I perform a linq query that orders my result in a group?

0

What I want to do is a group by in my linq query, but I do not really know what the correct syntax is so that it gets it right:

Current Code:

public List<Section> getSectionsClass()
{
    var context = GetDbContext();
    return (from cs in context.contenido_seccion
            join c in context.clase on cs.materiaId equals c.materiaId
            group cs by cs.id into gr
            select new Section()
            {
                Name = cs.nombre,
                Id = cs.id,
                IdClass = c.id
            }
    ).ToList();
}

I get an error after gr in select and the error says as follows:

Ambiguos invocation
    
asked by David 26.06.2018 в 20:48
source

1 answer

0

Very good I think the problem is that you try to access some table that is not in the scope due to the order of the query. Try this:

    public List<Section> getSectionsClass()
{
    var context = GetDbContext();
    return (from cs in context.contenido_seccion
            group cs by cs.id into gr
            join c in context.clase on gr.materiaId equals c.materiaId

            select new Section()
            {
                Name = gr.nombre,
                Id = gr.id,
                IdClass = c.id
            }
    ).ToList();
}
    
answered by 27.06.2018 в 09:03