1

sorry for my English, I need your help. I currently receive from the database this:

enter image description here

But I need to get this with linq, thank you very much for your help. the year column can increase

enter image description here

Edit: Code

var res = listaEnIndicaorList.GroupBy(x => new {x.ID_PE, x.ID_JERARQUIA, 
x.ID_INDICADOR})
            .Select(x => new
            {
                id_1 = x.Key.ID_PE,
                id_2 = x.Key.ID_JERARQUIA,
                id_3 = x.Key.ID_INDICADOR,
                Data = x.Select(d => d.ANIO).ToList()
            }).ToList();
devfar
  • 31
  • 2
  • I've tried it already but without success, thanks anyway – devfar Sep 26 '19 at 22:40
  • 1
    Please share so we could help you with that – Julian Sep 26 '19 at 22:41
  • The first thing to do when *researching* a problem is to learn the vocabulary. The kind of query you want is called a pivot query. Also note that a DB design with serialized column names (id_1, id_2, id_3, Des_1, des_2) is seriously flawed to begin with - it means some important relationships are not present – Ňɏssa Pøngjǣrdenlarp Sep 26 '19 at 22:50
  • @Ňɏssa Pøngjǣrdenlarp Thank you for your response, it is an example of what I am working on, and I have basic knowledge of linq, but I am learning and practicing. – devfar Sep 26 '19 at 23:02
  • @Julian ok, edit my question. – devfar Sep 26 '19 at 23:15
  • 2
    a good starting point. https://stackoverflow.com/questions/167304/is-it-possible-to-pivot-data-using-linq – smiggleworth Sep 27 '19 at 00:43
  • could you tell us what will be the value of on `2020, 2021, 2022, 2023` – Gabriel Llorico Sep 27 '19 at 03:29
  • Thanks @gabriel-llorico, I have updated the images, I would very much appreciate your help or any indication of how I could do it. – devfar Sep 27 '19 at 15:47
  • Possible duplicate of [Is it possible to Pivot data using LINQ?](https://stackoverflow.com/questions/167304/is-it-possible-to-pivot-data-using-linq) – Julian Sep 27 '19 at 23:46

0 Answers0