Can somebody please give an explanation to why I am getting this error with my LINQ code?
LINQ to Entities does not recognize the method 'System.String GenerateHashWithSalt(System.String, System.String)'method and this method cannot be translated into a store expression.
var query = (from u in context.Users
where
u.Password ==
GenerateHashWithSalt(password, GetUserID(username))
select u).Count();
You are trying to pass a method to EF which tries to convert that method to known SQL command.
SQL doesn't know about GenerateHashWithSalt(System.String, System.String)
You should first assign the result to a variable then generate your Linq to Entity Query.
Example
var hashedPassword = GenerateHashWithSalt(password, GetUserID(username));
var user = (from p in Users
where p.Password == hashedPassword
select p).FirstOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With