How can I fill a list field using EF and linq of this model
public class Infraccion
{
public int IdInfraccion { get; set; }
public string Serie { get; set; }
public int Numero { get; set; }
public Direccion Direccion { get; set; }
public string Comentario { get; set; }
public DateTime Fecha { get; set; }
public DateTime Hora { get; set; }
public string Dominio { get; set; }
public List<Contravencion> ListaDeContravenciones = new List<Contravencion>();
}
I DO know how to fill simple propertires, but dunno how to fill field List object where Contravencion is define like
public class Contravencion
{
public string Articulo { get; set; }
public string Inciso { get; set; }
public int IdContravencion { get; set; }
public string Descripcion { get; set; }
public int UfijasMinimo { get; set; }
public int UfijasMaximo { get; set; }
}
So far this is what I have
var listadoInfracciones = (from u in _context.Usuario
join ui in _context.UsuarioInfracciones on u.UsuarioId equals ui.UserId
join i in _context.Infraccion on ui.InfraccionId equals i.InfraccionId
join d in _context.Direcciones on i.IdDireccion equals d.DireccionId
where ui.UserId == usuario.IdUsuario
select new Infraccion
{
Comentario = i.Comentario,
Direccion = new Direccion
{
Calle = d.Calle,
Entre1 = d.Interseccion1,
Entre2 = d.Interseccion2
},
Dominio = i.Dominio,
Fecha = i.Fecha,
Numero = i.Numero,
Serie = i.Serie,
ListaDeContravenciones = new List<Contravencion>()
}).ToList();
Where can't find the right way to fill the list of Contravenciones
. Heres the DB model:
I've already seen these posts but do NOT fit my needs Easy way to fill object How to get data from the database into objectlists fast (with entity framework)