8
I have the following table:
USUARIO
Nome | Idade
João | 21
Maria | 18
I want to do in only one consultation return all users, or return only users of specific age based on a C variable#.
Also by name.
int idade = 18;
string nome = "";
var resultado = (from u in db.Usuario
// Se idade != 0 considerar o where.
// Caso contrário, trazer todos os usuarios.
where u.Nome == nome && u.Idade == idade).ToList();
How could I do that?
I’m using Entity Framework.
Perfect! The first option I had already thought about, but is that my query is actually much bigger and different in the posted question. Actually the second option will help me keep the code clean. It lacked logical thinking on my part.
– Jedaias Rodrigues
It’s a matter of opinion, in mine clean code is the first. Even if you have other things to add. I actually think with more things, it’s more important to do it that way.
– Maniero