Entity Linq consultation in many-to-many relationship

Asked

Viewed 153 times

1

I inherited a bank that is untouchable... despite having some very "strange" things. For example I have the following situation that would represent an n-n relationship but the relationship does not actually exist.

inserir a descrição da imagem aqui

In other words, a neighborhood can have many properties and a property can... have many neighborhoods. And to make the relationship between tbBairro and tbBairroImovel even worse doesn’t exist.

Now I need to search the bank for a list of all the properties that are on a list of neighborhoods. Kind of:

int[] ListaIdsBairros = { 10, 2, 37 };
imoveis = MeuContexot.tbImovel.Where(I => ListaIdsBairros.Contains(não sei o que por aqui));

I don’t even know if it’s possible to do this research on a single line. Will I have to make a looping in Listaidsbairros adding the return of real estate for each neighborhood in a general list of real estate???

Does anyone have an idea how to do this search?

Added later --------------------------------------------------

Today I can only do so:

List<tbImovel> ResultImoveis = new List<tbImovel>();
        foreach (var Bairro in ListaDeIds)
        {
            List<tbImovel> Imoveis = new List<tbImovel>();
            Imoveis = ctx.tbBairroImovel.Where(bi => bi.idBairro == Bairro.idBairro).Select(bi => bi.tbImovel).ToList();
            foreach(var imovel in Imoveis)
            {
                ResultImoveis.Add(imovel);
            }
        }

But I’m trying to make it better.

  • Is Lazy Loading enabled? This "flaw" in the mapping has been made to avoid problems with the serialization of this search, even if it is wrong.

No answers

Browser other questions tagged

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