String search in database using Linq C# wpf

Asked

Viewed 62 times

2

I have a bank and I want to run a search in the name field, but I also want the customer to be able to search for parts of the string or even with uppercase and minuscule letters. by the time my search works however the string has to be exactly like this in the bank.

using(ConsultorioContext ctx = new ConsultorioContext())
 {
     List<Produto> lista = ctx.Produtos.Where(p => p.Id == id || p.Nome == nome).ToList();
     return lista;
 }

1 answer

3


You can use the Contains, would look something like this:

using(ConsultorioContext ctx = new ConsultorioContext())
 {
     List<Produto> lista = ctx.Produtos.Where(p => p.Id == id || p.Nome.Contains(nome)).ToList();
     return lista;
 }

He’s like a man like of SQL.

  • I work perfectly, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.