Normalization of tables and Relationships

4

I'm starting a project from scratch and in the middle of modeling the bank, I had a problem. When I built the models , I could not do it right and I ended up confusing everything.

I have student information, occurrences and logins. Where I have several occurrences for a student and several occurrences for a login, to track which login is generating the instance.

But here's my problem: in my student table I have a lot of information like student's name, father's name, mother's name, responsible person's name, contact phone number, primary phone number, contact phone number, p>

I thought of putting the parents' names on a different table, just like the phones, to leave the tables with their respective objections, subjects. That is, organize the subjects. But in doing so, it spawned me several errors when doing scaffolding , since at first it only appeared as dropdown a phone and only the name of the parent. So you're missing data.

How would I do it? Would you leave all the information in one table? That is, would eliminate these tables of phones and parents, and leave this information in a table only, that of students? Or is not separating right by creating these two tables? And how would I do it?

The models :

Student

 //Aqui começa a declaração normal dos atributos
    public long Id { get; set; }

    public string TipoEnsino { get; set; }

    public string Nome { get; set; }

    public string Endereco { get; set; }

    public DateTime DataNascimento { get; set; }

    public DateTime AnoLetivo { get; set; }

    public int Ano { get; set; }

    public string Turma { get; set; }

    public int NumeroChamada { get; set; }

    public string Foto { get; set; }

    public string Observacoes { get; set; }
    //Aqui termina 

    //Aqui começa os relacionamentos

        //Ocorrencias
        public ICollection<Ocorrencia> Ocorrencias { get; set; }

        //Pais
        public long PaisId { get; set; }
        public Pais Pais { get; set; }

        //Telefone
        public long TelefoneId { get; set; }
        public Telefone Telefone { get; set; }
    //Aqui termina

Parents

 //Aqui começa a declaração normal dos atributos
    public long Id { get; set; }

    public string NomePai { get; set; }

    public string NomeMae { get; set; }

    public string NomeResponsavel { get; set; }
    //Aqui termina a declaração

    //Aqui começa os relacionamentos

        //Aluno
        public long AlunoId { get; set; }
        public Aluno Aluno { get; set; }
    //Aqui termina

Phone

//Aqui começa a declaração normal de atributos
    public long Id { get; set; }

    public string Contato { get; set; }

    public string Alternativo { get; set; }

    public string Responsavel { get; set; }
    //Aqui termina a declaração normal

    //Aqui começa os relacionamentos

        //Aluno
        public long AlunoId { get; set; }
        public Aluno Aluno { get; set; }
    //Aqui termina
    
asked by anonymous 27.10.2014 / 04:00

2 answers

7

I do not see the need to separate the information from Parent of Student, unless you want to make a table of Responsibles, whose cardinality for Student is 1 to N.

In any case, I'll assume that you just want to register father and mother, so the Aluno entity looks like this:

[DisplayColumn("Nome")]
public class Aluno 
{
    [Key]
    public long AlunoId { get; set; }

    public TipoEnsino TipoEnsino { get; set; } //TipoEnsino é um Enum

    [Required]
    public string Nome { get; set; }

    public string Endereco { get; set; }

    public DateTime DataNascimento { get; set; }

    public DateTime AnoLetivo { get; set; }

    public int Ano { get; set; }

    public string Turma { get; set; }

    public int NumeroChamada { get; set; }

    public string Foto { get; set; }

    public string NomePai { get; set; }

    public string NomeMae { get; set; }

    public string NomeResponsavel { get; set; }

    [NotMapped]
    public HttpPostedFileBase ArquivoFoto { get; set; }

    public string Observacoes { get; set; }

    //Ocorrencias
    public virtual ICollection<Ocorrencia> Ocorrencias { get; set; }

    //Telefone
    public virtual ICollection<Telefone> Telefones { get; set; }
}

Phone changed for cardinality N:

[DisplayColumn("Numero")]
public class Telefone 
{
    [Key]
    public long Id { get; set; }

    public TipoTelefone TipoTelefone { get; set; }

    public string Numero { get; set; }

    //Aluno
    public long AlunoId { get; set; }
    public virtual Aluno Aluno { get; set; }
}
    
02.11.2014 / 19:34
5

Regarding this, as Gypsy said, unless the students do not have the relationship with parents, but with those responsible. If it is only parents, we know that a person can only have 1 father and 1 mother (in thesis), so he could leave the information of each one together with the information of the Student. On phones, for the ratio being 1 to n I have a habit of seeing in numerous applications the use of an external table for both phone and email

    
03.11.2014 / 11:31