The code below fails with error:
LINQ to Entities does not recognize the method 'Boolean CompareNames(System.String, System.String)' method, and this method cannot be translated into a store expression.
I understand that my CompareNames
method cannot be converted to a SQL statement but want to know a way to accomplish this task without pulling the entire table from the database to compare.
// Use my method in Linq to Sql lambda
Repo.Get<T>(c => CompareNames(c.Name, newName)).ToList()
// Compare two names removing spaces and non-numeric characters
private static bool CompareNames(string str1, string str2)
{
str1 = Regex.Replace(str1.Trim(), "[^a-z,A-Z,0-9.]", "");
str2 = Regex.Replace(str2.Trim(), "[^a-z,A-Z,0-9.]", "");
return str1 == str2;
}