Hi @Rolando Ivan Medrano Chavez ,
As far as I think,you could create a collection and then map to your new model.Just like this:
var arrList = new List<MapModel>()
{
new MapModel() { Grupo=1, IdVariable = 1 ,Nombre="AA"},
new MapModel() {Grupo=1, IdVariable = 2,Nombre="BB" },
new MapModel() {Grupo=2, IdVariable = 13 ,Nombre="CC"},
};
var result = arrList.Select(
x => new
{
x.Grupo,
x.IdVariable,
x.Nombre
}).ToList();
var listResults = new List<IndexViewModel>();
if (result != null)
{
listResults.AddRange(result.GroupBy().Select(x => new IndexViewModel
{
// add to new model
}));
}
}
class IndexViewModel
{
public int Grupo { get; set; }
public List<MapModel> ListaConsultaVariable { get; set; }
}
Best regards,
Yijing Sun
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.