I have a query query for a report, where some search fields are optional except for date ranges.
However, when performing the query, the function always returns values that do not match the parameters I passed at the moment of executing the query
public List<IQueryable> ObterNotaDetalhada(DateTime compInicial, DateTime compFinal, PorteContribuinte? codigoPorte, string query, int? itemServico, bool? simplesNacional)
{
var res = this.Servicos
.Where(a => ((a.Competencia >= compInicial && a.Competencia <= compFinal) ||
(a.Prestador.Porte.Value == codigoPorte) || (a.Prestador.IsSimplesNacional == simplesNacional) ||
(a.ItemListaServico.Id == itemServico) ||
(a.Prestador.RazaoSocial.Contains(query) ||
a.Prestador.CpfCnpj.Contains(query))))
.OrderByDescending(a => (a.id))
.GroupBy(a => a.Prestador.CpfCnpj)
.Select(g => new
{
CNPJ = g.Key,
RazaoSocial = g.Select(x => x.Prestador.RazaoSocial),
SimplesNacional = g.Select(x => x.Prestador.IsSimplesNacional),
Porte = g.Select(x => x.Prestador.Porte),
QtdNotasEmitidas = g.Count(),
BaseDeCalculo = g.Select(x => x.BaseCalculo),
ValorDeducoes = g.Select(x => x.ValorDeducoes),
ValorServicos = g.Select(x => x.ValorServicos),
ValorIss = g.Select(x => x.ValorInss),
TotalBaseDeCalculo = g.Sum(x => x.BaseCalculo),
TotalValorDeducoes = g.Sum(x => x.ValorDeducoes),
TotalValorServicos = g.Sum(x => x.ValorServicos),
TotalValorIss = g.Sum(x => x.ValorIss),
IssRetido = g.Select(x => x.IssRetido > decimal.Zero),
ItemDeServico = g.Select(x => x.ItemListaServico.Descricao),
CodItemServico = g.Select(x=>x.ItemListaServico.Codigo)
});
return new List<IQueryable> { res };
}
The parameters that I submit to the method:
Note:WhenIsearchonlythedaterange,itreturnseverythingcorrectly.
Anexamplesearchresult: