Answer the question
In order to leave comments, you need to log in
Why does the compiler swear at the method in the delegate passed to FirstOrDefault?
Call
user = db.Users.FirstOrDefault(u => u.Login == loginTextBox.Text && u.PasswordHash == GetMD5Hash(passwordTextBox.Text));
public static string GetMD5Hash(string str)
{
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
stringBuilder.Append(hash[i].ToString("x2"));
}
return stringBuilder.ToString();
}
Answer the question
In order to leave comments, you need to log in
In this case, LINQ is trying to convert a LINQ query into a server-side SQL query, and a method such as GetMD5Hash does not exist for it, so it throws an error. When converting, it does not first execute the GetMD5Hash method, with a continuation, but immediately tries to get the SQL code. Therefore, in this case, it can simply be taken out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question