I have a problem with WCF Service operation. I get passwod value from database and when it should pass it return false value. What am I doing wrong?
public bool LogIn(string userId, string passwd)
{
bool prompt;
ProgDBEntities context = new ProgDBEntities();
IQueryable<string> haslo = (from p in context.UserEntity where p.UserID == userId select p.Passwd);
bool passOk = String.Equals(haslo, passwd);
if (passOk == true )
{
prompt = true;
}
else
{
prompt = false;
}
return prompt;
}
It seems like you want to compare a single retrieved entry with the password that was passed in (as opposed to any IQueryable/IEnumerable). For that, try using the FirstOrDefault method:
public bool LogIn(string userId, string passwd)
{
bool prompt;
ProgDBEntities context = new ProgDBEntities();
var haslo = (from p in context.UserEntity where p.UserID == userId select p.Passwd).FirstOrDefault();
// No need to use String.Equals explicitly
bool passOk = haslo == passwd;
if (passOk == true )
{
prompt = true;
}
else
{
prompt = false;
}
return prompt;
}