1
I have the following classes
public class ControleDeVisitas
{
public virtual ICollection<TipoDeSistemas> TipoDeSistemas { get; set; }
}
public class TipoDeSistemas
{
public Guid TipoDeSistemasId { get; set; }
public string Descricao { get; set; }
public DateTime DataCadastro { get; set; }
}
thus, in the table, TIPO DE SISTEMAS
, a key is being created ControleDeVisitaId
this is the method I use to add a TipoDeSistema
at the Controle
public ControleDeVisitasViewModel Adicionar(ControleDeVisitasViewModel controleDeVisitasViewModel, List<Guid> sistemasComerciais)
{
var controle = Mapper.Map<ControleDeVisitas>(controleDeVisitasViewModel);
foreach (var sistema in sistemasComerciais)
{
var ts = _tipoDeSistemaRepositorio.BuscarPorId(sistema);
controle.TipoDeSistemas.Add(ts);
}
_controleDeVisitaRepositorio.Adicionar(controle);
}
and that’s how the tebela is getting TipoDeSistemas
I erased some data, but the truth is, it’s duplicating the same information, like, if I choose system A, B and C.(both should already be registered).
it creates a new system of type A, B and C in the same table. and puts the Control key.
someone knows me why he is creating this key in the table TipoDeSistema
?
so is my config:
public ControleDeVisitasConfig()
{
ToTable("ControleDeVisitas");
HasKey(c => c.ControleDeVisitasId);
HasMany(c => c.TipoDeSistemas);
}