C # - AsQueryable - Condition (Linq - Lambda)

0

In this method, I populate my 'rule' variable with all rules coming from Select, but I'd like to filter only the Status = True. How to do this?

  public async Task<BootgridResponseViewModel<ConsultaIntramexRegrasResponse>> ObterListaRegrasConsultaIntramex(BootgridRequestViewModel request)
    {
        using (var ctx = new IntramexContext())
        {
            var regras = ctx.ConsultaIntramexRegras.AsQueryable().Select(p => new ConsultaIntramexRegrasResponse
            {
                Id = p.Id,
                Descricao = p.Descricao,
                Periodicidade = p.Periodicidade,
                DiaSemanaMes = p.DiaSemanaMes,
                Horario = p.Horario,
                CodigoConsulta = p.CodigoConsulta,
                OperadorRegistroId = p.OperadorRegistroId,
                Status = p.Status,
                UltimaExecucao = p.UltimaExecucao
            }).Distinct();


            if (!string.IsNullOrWhiteSpace(request.searchPhrase))
            {
                regras = regras.Where(p => p.Descricao.Contains(request.searchPhrase)
                          || p.Periodicidade.ToString().Contains(request.searchPhrase)
                          || p.Descricao.ToString().Contains(request.searchPhrase)
                          || p.OperadorRegistroId.ToString().Contains(request.searchPhrase));
            }

            var dados = await regras.OrderByDescending(m => m.Id).AplicaFiltroAsync(request).ConfigureAwait(false);
            return dados;
        }
    }
    
asked by anonymous 15.06.2018 / 15:11

1 answer

1

var regras = ctx.ConsultaIntramexRegras.Where(r => r.Status)
                                       .Select(p => new ConsultaIntramexRegrasResponse { })

// Continuar o código normalmente
    
15.06.2018 / 15:20