0
It’s pretty simple stuff. I have a method that takes a name inside a database and compares it with the parameter passed in the method and be equal, return it in the method, otherwise return a string.Empty
. Turns out, I’m having a hard time doing it in a single row on my lambda. I did, but I had to fill a list on the lambda and then run the flat one foreach
and compare item by item and know that in my expression, I can get on the same line and delete the foreach
and the if
. The break
was not to continue after having found, I can have a large list and would generate unnecessary processing. See the method below:
private CotacaoContext contexto = new CotacaoContext();
[AcceptVerbs("Get")]
public string GetUsuarioLogin(string user)
{
var lista = new List<string>();
string nomeusuario = string.Empty;
contexto.Usuario.AsEnumerable().ToList().ForEach(u => lista.Add(u.NMUsuario.ToList().ToString()));
foreach (var l in lista)
{
if (l == user)
{
nomeusuario = user;
break;
}
}
return nomeusuario;
}
}
LINQ, that piece
? user : ""
makes all the difference. These Tostring(), Asenumerable() and etc, I put because I was making a mistake, but what was really missing was the "conclusion" of the expression, as I said. Thank you very much.– pnet