Database inheritance

2

I'm developing an application, where I have 3 tables that have the same attributes, but since they had attributes in those tables that were mandatory for some, not for others, I decided to separate them into 3 different tables. However, I'm having some trouble developing some functions that are common to all 3 tables.

What would be the best way to turn these 3 tables into one? Remembering that I have different data validation models for each table, then I do not think I could simply go away with the other two.

I'm using asp.net mvc 4 and entity framework with database first.

Table Usuario

    [IdUsuario] int IDENTITY(1,1) NOT NULL,
    [NomeCompleto] varchar(100)  NOT NULL,
    [Email] varchar(100)  NOT NULL,
    [Senha] varchar(45)  NOT NULL,
    [Sexo] char(1)  NULL,
    [Telefone] varchar(45)  NULL,
    [About] varchar(500)  NULL,
    [Nickname] varchar(45)  NOT NULL,
    [Email2] varchar(100)  NOT NULL,
    [Endereco] varchar(100)  NULL,
    [Bairro] varchar(45)  NULL,
    [Estado] varchar(45)  NULL,
    [Cep] varchar(11)  NULL,
    [Celular] varchar(45)  NULL,
    [FotoPerfil] varchar(500)  NULL,
    [StatusPerfil] varchar(100)  NULL,
    [NBans] int  NULL,
    [Banido] bit  NULL,
    [DtCadastro] datetime  NOT NULL,
    [DtNasc] datetime  NOT NULL

Table Banca 

    [IdBanca] int IDENTITY(1,1) NOT NULL,
    [NomeCompleto] varchar(100)  NOT NULL,
    [Cpf] char(11)  NOT NULL,
    [Email] varchar(100)  NOT NULL,
    [Rg] char(8)  NOT NULL,
    [Senha] varchar(45)  NOT NULL,
    [Sexo] varchar(45)  NOT NULL,
    [DtNasc] datetime  NULL,
    [Telefone] varchar(45)  NULL,
    [About] varchar(500)  NULL,
    [Nickname] varchar(45)  NOT NULL,
    [Email2] varchar(100)  NULL,
    [Endereco] varchar(100)  NOT NULL,
    [Bairro] varchar(45)  NOT NULL,
    [Estado] varchar(45)  NOT NULL,
    [Cep] varchar(45)  NOT NULL,
    [Celular] varchar(45)  NOT NULL,
    [Foto] varchar(500)  NULL,
    [FormAcademica] varchar(45)  NOT NULL,
    [DtCadastro] datetime  NOT NULL

Table Desginer
    [IdDesigner] int IDENTITY(1,1) NOT NULL,
    [NomeCompleto] varchar(100)  NOT NULL,
    [Cpf] char(11)  NOT NULL,
    [Email] varchar(100)  NOT NULL,
    [Rg] char(8)  NOT NULL,
    [Senha] varchar(45)  NOT NULL,
    [Sexo] varchar(45)  NOT NULL,
    [DtNasc] datetime  NULL,
    [Telefone] varchar(45)  NULL,
    [About] varchar(500)  NULL,
    [Nickname] varchar(45)  NULL,
    [Email2] varchar(100)  NULL,
    [Endereco] varchar(100)  NOT NULL,
    [Bairro] varchar(45)  NOT NULL,
    [Estado] varchar(45)  NOT NULL,
    [Cep] varchar(45)  NOT NULL,
    [Celular] varchar(45)  NULL,
    [Foto] varchar(500)  NULL,
    [DtCadastro] datetime  NULL
    
asked by anonymous 10.11.2014 / 23:51

1 answer

1

From what I understand Design and Banking are types of User.

You can use a table only and create one more field in that table (User Type for example), to identify the user type.

This field can even facilitate the implementation of your business rules related to users, for example:

var usuario = _repositorio.ObterUsuarioPorId(id);

if(usuario.TipoUsuario == EnumTipoUsuario.Design)
{
    //regra para usuário tipo Design
}

if(usuario.TipoUsuario == EnumTipoUsuario.Banca)
{
    //regra para usuário tipo Banca
}
  

... Remembering that I have different data validation models for each table, then I do not think I could simply go away with the other two ...

In fact, by analyzing the question information, I believe you have different data validations for each user object type . If it is a user of the type Design valid this / I make such logic, if it is user of the Banking type I need to validate that. But the table is the same, we're talking about the user.

    
11.11.2014 / 18:02