Problems Querying a Record Using the EntityFramework Core

0

I have a one-to-many relationship between the "Person" and "Person" tables. My idea is to have a People register (Register anyone other than a customer, an affiliate, or a supplier ... just a person). When a person is going to become a customer, for example, I play their Id in the Customer table and it is solved ... Only because of my need, a person will have an ID when registered in the people table and will have a different ID when she's a customer ... That's where the PersonEntity table comes in. In it I can create Codes for each Type of person.

UnderstandingBest:

IhavetworelationshipsbetweenPersonandPerson.Entity:"Person Relation" and "Personal Person Relation."

A Person can have several types of PersonPeople and a PersonPeople can only be tied to a Person and a PersonFilial can have several types of PersonPeople and a Person can only be tied to a Person. See the Navigation Properties:

public class Pessoa
{
    public virtual PessoaNatureza PessoaNatureza { get; private set; }
    public virtual PessoaFisica PessoaFisica { get; private set; }
    public virtual PessoaJuridica PessoaJuridica { get; private set; }
    public virtual ICollection<PessoaEntidade> PessoasEntidades { get; private set; }
    public virtual ICollection<PessoaEntidade> PessoasEntidadesFiliais { get; private set; }        
}
 public class PessoaEntidade
 {
     public int Id { get; private set; }
     public int PessoaId { get; private set; }
     public int PessoaFilialId { get; private set; }
     public DateTime DataInclusao { get; private set; }

     public virtual PessoaTipo PessoaTipo { get; private set; }
     public virtual Pessoa Pessoa { get; private set; }
     public virtual Pessoa PessoaFilial { get; private set; }
 }

Now, let's get down to the problem:

When I search a Person for the Id and it returns me a record, but it is returning the Person and PersonFilial list with the records that have nothing to do with the relationship ... Since the Person and PersonFilial Properties are of the type Person, it seems to understand that they are one thing only ... Is there any way I can improve my return function so that it can relate this correctly?

public Pessoa GetJoinById(int id)
{
    return DbSet
        .Include(pe=> pe.PessoasEntidades)
        .Include(pe => pe.PessoasEntidadesFiliais)
        .Include(pe => pe.PessoaJuridica)
        .Include(pe => pe.PessoaFisica)
        .FirstOrDefault(x => x.Id == id);         

}  
    
asked by anonymous 11.04.2018 / 23:10

0 answers