I am having a question about modeling a DesktopApplication system in C # with MySQL.
Essentially I will have the Client, Supplier, PF and PJ entities. PF can be a customer or supplier. And PJ can also be a customer or supplier. My goal is to use Entity Framework and my biggest concern is with query performance, records listings and reports. I have seen several approaches and discussions about it, but nothing conclusive.
Anyway, I'm in doubt among the 3 modeling options below:
Option 1:
CLIENTE
-id_cliente
FORNECEDOR
-id_fornecedor
PF
-id_pf
-id_cliente (não obrigatório)
-id_fornecedor (não obrigatório)
PJ
-id_pj
-id_cliente (não obrigatório)
-id_fornecedor (não obrigatório)
Option 2:
CLIENTE
-id_cliente
-id_pj (não obrigatório)
-id_pf (não obrigatório)
FORNECEDOR
-id_fornecedor
-id_pj (não obrigatório)
-id_pf (não obrigatório)
PF
-id_pf
PJ
-id_pj
Option 3 (which I used to use):
CLIENTE
-id_cliente
-id_pessoa (obrigatório)
-tipo (para indicar se o id_pessoa é na tabela PF ou PJ)
FORNECEDOR
-id_fornecedor
-id_pessoa (obrigatório)
-tipo (para indicar se o id_pessoa é na tabela PF ou PJ)
PF
-id_pf
PJ
-id_pj
I do not know what the C # template looks like in this 3rd option. I know that at the bank only level, it would be more efficient, but what would the models look like in C #? I do not think he would understand this form.
Could anyone give guidance to resolve this impasse? If you can give examples of implementing queries for the best suggestion I will be immensely grateful!
Based on the excellent answers you gave me, I built the template as follows:
However,generatingthemodelslookslikethis:
[Table("pessoa")]
public partial class pessoa
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public pessoa()
{
cliente = new HashSet<cliente>();
fornecedor = new HashSet<fornecedor>();
pessoafisica = new HashSet<pessoafisica>();
pessoajuridica = new HashSet<pessoajuridica>();
}
[Key]
public int idPessoa { get; set; }
[Required]
[StringLength(90)]
public string nomeRazaoSocial { get; set; }
public bool pf { get; set; }
}
[Table("pessoafisica")]
public partial class pessoafisica
{
[Key]
public int idPessoaFisica { get; set; }
[StringLength(15)]
public string cpf { get; set; }
public int idPessoa { get; set; }
public virtual pessoa pessoa { get; set; }
}
[Table("pessoajuridica")]
public partial class pessoajuridica
{
[Key]
public int idPessoaJuridica { get; set; }
[StringLength(45)]
public string cnpj { get; set; }
public int idPessoa { get; set; }
public virtual pessoa pessoa { get; set; }
}
That is, there was no specialization at the code level.
Speaking in practical terms! If I want to put together a listing of all people, with the columns person_id, NameOrSocial, CPF / CNPJ.
In this case I would have to use if else to know if it is PF or PJ and to know if I search the information in the personal or personal object?
Is there any strategy in Entity so that the person object knows where it should get this information from?
What would be the high-level solution for this issue?
Once again thank you!