Error with Mapping and Fluent Api

0

I have now started the study in Asp.Net MVC with EntityFramework, I am taking some time to save the following case:

public class Aluno
{
    public int Codigo { get; set; }
    public string Nome { get; set; }
    public DateTime DataNascimento { get; set; }

    public virtual IList<Afericao> RelacaoAfericoes { get; set; }
}

public class Professor
{
    public int Codigo { get; set; }
    public string Nome { get; set; }
    public DateTime DataNascimento { get; set; }
}

public class Afericao
{
    public int Codigo { get; set; }
    public int ProfessorId { get; set; }
    public virtual Professor Professor { get; set; }
    public int AlunoId { get; set; }
    public virtual Aluno Aluno { get; set; }
    public float Peso { get; set; }
    public float Altura { get; set; }
}

public class AlunoConfiguration : EntityTypeConfiguration<Aluno>
{
    public AlunoConfiguration()
    {
        ToTable("Alunos");

        HasKey(p => p.Codigo);

        Property(p => p.Codigo)
            .HasColumnName("AlunoId");

        Property(p => p.Nome)
            .HasColumnName("Nome")
            .IsRequired();

        Property(p => p.DataNascimento)
            .HasColumnName("DataNascimento")
            .IsRequired();
    }
}

public class ProfessorConfiguration : EntityTypeConfiguration<Professor>
{
    public ProfessorConfiguration()
    {
        ToTable("Professores");

        HasKey(p => p.Codigo);

        Property(p => p.Codigo)
            .HasColumnName("ProfessorId");

        Property(p => p.Nome)
            .HasColumnName("Nome")
            .IsRequired();

        Property(p => p.DataNascimento)
            .HasColumnName("DataNascimento")
            .IsRequired();
    }
}

public class AfericaoConfiguration : EntityTypeConfiguration<Afericao>
{
    public AfericaoConfiguration()
    {
        ToTable("Afericoes");

        HasKey(af => af.Codigo);

        Property(af => af.Codigo)
            .HasColumnName("AfericaoId");

        Property(af => af.ProfessorId)
            .HasColumnName("ProfessorId");

        HasRequired(af => af.Professor)
            .WithMany()
            .HasForeignKey(af => af.ProfessorId);

        Property(af => af.AlunoId)
            .HasColumnName("AlunoId");

        HasRequired(af => af.Aluno)
            .WithMany(a => a.RelacaoAfericoes)
            .HasForeignKey(af => af.AlunoId);

        Property(af => af.Peso)
            .HasColumnName("Peso");

        Property(af => af.Altura)
            .HasColumnName("Altura");
    }
}

I can include a Student, Teacher and Gauge, after inserting a gauge it is giving error. Would anyone know how to answer me?

And another question:

Contexto.Alunos.Include("RelacaoAfericoes")
                                  .Where(x => x.Codigo == pAlunoId).FirstOrDefault();

Why not return the list of RelationAssessment?

    
asked by anonymous 03.10.2016 / 23:19

0 answers