How to use the Where clause with Inno?

Asked

Viewed 159 times

0

I need to make a Join between the person and people tables so that the core Entity Framework brings a corresponding record. Let me be clearer:

In the personal tableentity, I sort my register of people using an Enum. I did this to save the Ids of each registration (Person, Customer, supplier, etc). If a person is a customer they will have an ID, if they are a Supplier they will have another ID and if they are neither, they will have their ID.

inserir a descrição da imagem aqui

At the moment, I need to get in the bank and bring all the people who are physical/legal and who are PERSON type.So I need to give a Join in the Personal table entity and do a Where informing to bring only type 0 - PERSON. How do I do this using LINQ?

public IQueryable<Pessoa> GetJoinAll()
        {
            var pessoas = 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();
        }
  • 1

    after last include use . Where(x => x.PersonalEntitytype == 0). toList();

  • Relacionado https://answall.com/q/82752/101 e https://answall.com/q/153264/101 e https://answall.com/q/184843/101 e https://answall.com/q/182176/101 e

2 answers

0

Basically it would 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();
    }

0

You have to go through the Object:

{

var people = Db.Person.Getall(). Where(a=> a.PersonNatureza.Persontype == 0). Tolist();

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.