The thing is very simple indeed. I have a method that takes a name inside a database and compares with the parameter passed in the method and being is equal, return it in the method, otherwise return a string.Empty
. It turns out, I'm having difficulty doing in a single line in my lambda. I did, but I had to fill a list in lambda and then loop through a foreach
and compare item to item and I know that in my expression, I can get on the same line and delete foreach
and if
. break
was not to continue after encountering, I may 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;
}
}