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