I would like to know how best to construct a query that looks in all the fields of a table.
Let's say I have a news site, and on this site I have input
to Search
in my template. When typing the information in this template, it needs to search in several columns in the table, such as title, description, author, etc. What is the best way to do this?
One way to do this search is to use IFs
, but let's face it that it is not good to use. And from this premise comes my doubt.
An example would be:
public ActionResult Buscar(string texto)
{
var titulo= AppService.ObterPorTitulo(texto);
if (!titulo.Any())
{
var descricao= AppService.ObterPorDescricao(texto);
if (!titulo.Any())
{
var autor= AppService.ObterPorAutor(texto);
return View("index", autor);
}
return View("index", descricao);
}
return View("Index", titulo);
}
I think this would be a "gambiarra . Then comes my question: How to search all fields in a single Action