How to use the where clause with linq?

0

I need to make a join between the person and person tables so that the Entity Framework core brings a corresponding record. I'll be clearer:

In the Person Person table, I classify my people record using an enum. I did this to save the Ids of each register (Person, Customer, Vendor, etc). If a person is a customer, they will have an ID, if they are a Vendor, they will have another ID and if they are neither, they will have their ID.

Atthemoment,Ineedtogiveagetinthebankandbringallpeoplethatarephysical/legalandthatareoftypePERSON.SoIneedtogiveajoininthePersonEntitytableandmakeawherereportingtobringonlyoftype0-PERSON.HowdoIdothisusingLINQ?

publicIQueryable<Pessoa>GetJoinAll(){varpessoas=Db.Pessoa.Include("PessoaEntidade")
                .Include("Filial")
                .ToList();

            pessoas.ForEach(x =>
            {
                if (x.PessoaNatureza == PessoaNatureza.Fisica)
                {
                    Db.Entry(x)
                        .Reference(f => f.PessoaFisica)
                        .Load();
                }
                else
                {
                    Db.Entry(x)
                        .Reference(j => j.PessoaJuridica)
                        .Load();
                }

            });


            return pessoas.AsQueryable();
        }
    
asked by anonymous 05.04.2018 / 16:55

2 answers

0

You have to go through the object:

{

}

    
07.04.2018 / 02:45
0

It would basically look like this:

    public IQueryable<Pessoa> GetJoinAll()
    {
        var pessoas = Db.Pessoa
            .Include("PessoaEntidade")
            .Include("Filial")
            .Where(p => p.PessoaEntidade.PessoaTipo == PessoaTipo.Pessoa)
            .ToList();

        pessoas.ForEach(x =>
        {
            if (x.PessoaNatureza == PessoaNatureza.Fisica)
            {
                Db.Entry(x)
                    .Reference(f => f.PessoaFisica)
                    .Load();
            }
            else
            {
                Db.Entry(x)
                    .Reference(j => j.PessoaJuridica)
                    .Load();
            }

        });


        return pessoas.AsQueryable();
    }
    
28.04.2018 / 14:31