2
I don’t understand the reason for this error in Entity. Could you give me a help?
Error: The role 'Occurrence_occurrence_target' of the Relationship 'Addresseb.Models.Occurrence_occurrence' has multiplicity 1 or 0.. 1.
Model:
public partial class Ocorrencia
{
[Key]
public int id { get; set; }
public Pessoa Pessoa { get; set; }
public int? PessoaId { get; set; }
public virtual ICollection<OcorrenciaHistorico> Historico { get; set; }
public Ocorrencia()
{
Historico = new HashSet<OcorrenciaHistorico>();
}
}
public class Pessoa
{
[Key]
public int id { get; set; }
public string nome { get; set; }
}
public class Historico
{
[Key]
public int id { get; set; }
public DateTime DataCadastro { get; set; }
public Pessoa pessoa { get; set; }
public int pessoaId { get; set; }
public int OcorrenciaId { get; set; }
public virtual Ocorrencia Ocorrencia { get; set; }
}
The error happens when saving after adding an object to the history.
Ocorrencia.Historico.Add(new OcorrenciaHistorico() { Acao = "Criação", DataCadastro = DateTime.Now, Ocorrencia = Ocorrencia, pessoa = pessoa });
What’s the rest of the mistake?
– Leonel Sanches da Silva
@Ciganomorrisonmendez I edited the question adding this information.
– Bruno Heringer