My scenery:
public class AlunoAvaliacao
{
public int AlunoAvaliacaoID { get; set; }
public DateTime Inicio { get; set; }
public DateTime? Fim { get; set; }
public virtual int AvaliacaoID { get; set; }
public virtual Avaliacao Avaliacao { get; set; }
public virtual int AlunoID { get; set; }
public virtual Aluno Aluno { get; set; }
public virtual ICollection<AlunoAvaliacaoPergunta> AlunoAvaliacaoPerguntas { get; set; }
}
public class AlunoAvaliacaoPergunta
{
public int AlunoAvaliacaoPerguntaID { get; set; }
public virtual int AlunoAvaliacaoID { get; set; }
public virtual AlunoAvaliacao AlunoAvaliacao { get; set; }
public virtual int AvaliacaoPerguntaID { get; set; }
public virtual AvaliacaoPergunta AvaliacaoPergunta { get; set; }
public string Resposta { get; set; }
public bool Correta { get; set; }
}
var alunoAvaliacao = new AlunoAvaliacao();
alunoAvaliacao.Aluno = aluno;
alunoAvaliacao.Avaliacao = avaliacao;
alunoAvaliacao.Inicio = DateTime.Now;
alunoAvaliacao.AlunoAvaliacaoPerguntas = new List<AlunoAvaliacaoPergunta>();
bdAlunoAvaliacao.Adicionar(alunoAvaliacao);
bdAlunoAvaliacao.SalvarTodos();
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: An object of type 'System.Collections.Generic.List'1 [[Application.Creat.Domination.AvalationQuestion, Aplicacao.Core, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null]] 'can not be set or removed from the Value property of an EntityReference of type 'Application.Creat.Domination.AvalationQuestion'.
I have tried modelBuilder
... And nothing. Why this error?