Hello,
I have a problem to assign a list of one type of model to another of another type of model What I need to do is the following,
From SQL I get a list with the following fields
Grupo, IdVariable, Nombre, Operador, Condicional
The fact is that I have a model that is adapted to support that structure
My model is the following:
public class ConsultaVariableListadoModel
{
private short _Grupo;
private int _IdVariable;
private string _Nombre;
private string _Operador;
private string _Condicional;
public short Grupo
{
get { return _Grupo; }
set { _Grupo = value; }
}
public int IdVariable
{
get { return _IdVariable; }
set { _IdVariable = value; }
}
public string Nombre
{
get { return _Nombre; }
set { _Nombre = value; }
}
public string Operador
{
get { return _Operador; }
set { _Operador = value; }
}
public string Condicional
{
get { return _Condicional; }
set { _Condicional = value; }
}
}
But I need to group that record by grupo field so create another model
public class GrupoListadoModel
{
private short _Grupo;
private List<ConsultaVariableListadoModel> _ListaConsultaVariable;
public short Grupo
{
get { return _Grupo; }
set { _Grupo = value; }
}
public List<ConsultaVariableListadoModel> ListaConsultaVariable
{
get { return _ListaConsultaVariable; }
set { _ListaConsultaVariable = value; }
}
}
I need to assign the records of the first list to the new model, but I don't know how to do it
List<ConsultaVariableListadoModel> arrList = new List<ConsultaVariableListadoModel>();
arrList = this._VariableRepository.FiltrarConsultaVariable(idConsulta);
List<GrupoListadoModel> arrList2 = new List<GrupoListadoModel>();
arrList2 = arrList.Select(u => u.Grupo).Distinct();
from the arrayList I want to add the grupo field and make the other fields child,
in advance I appreciate your help