Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

565
Visualizações
EF Core 3.1 - Include filtering throw an error 'Lambda expression used inside Include is not valid.'

I have Item table(Main) and ItemAlt table(Sub (List)) I want to get all item alt rows where:

  1. ItemAlt.WarehouseId is equal to parameter warehouseId

  2. Item.Id is equal to parameter itemId

    public async Task<Item> GetItemWithAlt(int itemId, int warehouseId)
    {
        var query = from i in _dbContext.Item.Include(a => a.ItemAlt.Where(c => c.WarehouseId == warehouseId && c.IsActive == true))
                    where i.IsActive.Equals(true) && i.Id.Equals(itemId)
                    select i;
        return await query.SingleOrDefaultAsync();
    }
    

the problem is it throws the exception "Lambda expression used inside Include is not valid" in

.Where(c => c.WarehouseId == warehouseId && c.IsActive == true)

Do you know how to get around this issue?

  • I already tried searching for the error message but the queries are different from mine
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Filtered includes are available only since EF Core 5.0 as docs state:

This feature was introduced in EF Core 5.0.

So you need either to update your project to corresponding .NET and EF Core versions or rewrite query to manual join with filtered ItemAlt's.

Or try to select into anonymous type and rely on the relationship fixup. Something along this lines (not tested):

var result = await _dbContext.Item
    .Where(i => i.IsActive.Equals(true) && i.Id.Equals(itemId))
    .Select(i => new 
    {
        Item = i,
        ItemAlts = i.ItemAlt
            .Where(c => c.WarehouseId == warehouseId && c.IsActive == true))
            .ToList()
    }
    .SingleOrDefaultAsync();

return result?.Item;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda