1
I have a query that returns me all the columns and I’m using only two columns (id
and nome
) in my select2
, I thought to bring only these columns, I wonder if it is possible to bring in the query only two columns Fornecedor
.
I got the following:
Ifornecedorrepository
Task<IEnumerable<Fornecedor>> ObterParaAutocomplete(string text);
Vendordorrepository
public async Task<IEnumerable<Fornecedor>> ObterParaAutocomplete(string text)
{
return await Db.Fornecedores.AsNoTracking()
.Where(x => x.Nome.Contains(text))
.OrderBy(p => p.Nome)
.ToListAsync();
}
Suppliers
[HttpGet]
public async Task<IActionResult> ObterFornecedor(string text)
{
if (string.IsNullOrEmpty(text))
{
return Json(new
{
result = ""
});
}
else
{
var dados = _mapper
.Map<IEnumerable<FornecedorViewModel>>(
await _fornecedorRepository.ObterParaAutocomplete(text)
);
return Json(new
{
result = dados
});
}
}
Json result
No solution worked out?
– novic
@Virgilionovic all right! Thank you!
– Harry