I have two classes: Pessoa
and Usuario
. The Usuario
class inherits the properties and methods of the Pessoa
class.
I'm using the Entity Framework and I believe you're doing the wrong mapping. So the problem is happening as shown below.
The rule would be: A person can be multiple users registered (seems to be wrong logic, but it is because of my need) and a user can only be linked to a person.
CodeMappingofthePersonclass
publicPessoaConfiguration(){ToTable("tblPessoa");
HasKey(p => p.PessoaId);
Property(p => p.DataInclusao).IsRequired();
}
User Class Mapping Code
public UsuarioConfiguration()
{
ToTable("tblUsuario");
HasKey(p => p.UsuarioId);
HasRequired(p => p.Pessoa)
.WithMany(u => u.Usuarios)
.HasForeignKey(p => p.PessoaId);
Property(c => c.NomeUsuario).HasColumnName("NomeUsuario")
.HasColumnType("Varchar")
.HasMaxLength(25)
.IsRequired();
Property(c => c.Senha).HasColumnName("Senha")
.HasColumnType("Varchar")
.HasMaxLength(25)
.IsRequired();
}
Note: The image is specifying how the table should be in the database.