Problem comparing 2 lists

Asked

Viewed 59 times

0

I have a problem, I need to make a filter with a list of strings that comes as parameter with a icollection, the visual studio accuses

"Cannot Convert from List to Unidadefederativaforedor"

What could be done in this case? This is the code:

public HttpResponseMessage GetPotenciaisFornecedoresProduto(int id, [FromUriAttribute] List<int> marcas, int dias, List<string> unfed ,int? take = 20, int skip = 0)
    {
        DateTime dataDaOperacao = DateTime.Now;
        dataDaOperacao = dataDaOperacao.AddDays(-dias);



        var ofertas = FornecedorCotacaoService.GetAll()
            .Where(c => c.FornecedorProdMarcaCotacao.Any(o => o.ProdutoMarca.IdProduto == id
                                                      && (marcas.Contains(o.ProdutoMarca.IdMarca)
                                                      && (c.Cotacao.DtCadastro >= dataDaOperacao)
                                                      && *c.Fornecedor.UnidadeFederativaFornecedor.Contains(unfed)*)
                  ))
            .GroupBy(c => new { c.IdFornecedor, c.Fornecedor.Pessoa.NmPessoa, c.Fornecedor.Pessoa.EnderecoFatura.IdUnidadeFederativa })
            .Select(c => new { c.Key.IdFornecedor, c.Key.NmPessoa, c.Key.IdUnidadeFederativa, Count = c.Count() })
            .ToList();
  • If you look at the documentation you will see that the contains is as follows List<T>. Contains(T) being the’T' type in question, note that in your case you are picking up a list of the type Unidadefederativaforedor and this trying to use contains with a list of strings

  • Any hints of what could be done ?

1 answer

0


At the point in question, you could use a . Any instead of . Contains, and inside . Any use Contains to check your string.

&& c.Fornecedor.UnidadeFederativaFornecedor.Any(uff => undef.Contains(uff.PropriedadeStringQueRepresentaUNDEF))

Browser other questions tagged

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