Levenshtein Distance Linq 선택 쿼리를 사용하려고합니다 (아래 그림 참조). 예외가 발생합니다.Linq to Entities : 메서드를 인식하지 못합니다.
IEnumerable<Host> closeNeighbours = (from h in _dbContext.People
let lD = Utilities.LevenshteinDistance(lastName, h.LastName)
let length = Math.Max(h.LastName.Length, LastName.Length)
let score = 1.0 - (double)lD/length
where score > fuzziness
select h);
public static int LevenshteinDistance(string src, string dest)
{
int[,] d = new int[src.Length + 1, dest.Length + 1];
int i, j, cost;
char[] str1 = src.ToCharArray();
char[] str2 = dest.ToCharArray();
for (i = 0; i <= str1.Length; i++)
{
d[i, 0] = i;
}
for (j = 0; j <= str2.Length; j++)
{
d[0, j] = j;
}
for (i = 1; i <= str1.Length; i++)
{
for (j = 1; j <= str2.Length; j++)
{
if (str1[i - 1] == str2[j - 1])
cost = 0;
else
cost = 1;
d[i, j] =
Math.Min(
d[i - 1, j] + 1, // Deletion
Math.Min(
d[i, j - 1] + 1, // Insertion
d[i - 1, j - 1] + cost)); // Substitution
if ((i > 1) && (j > 1) && (str1[i - 1] ==
str2[j - 2]) && (str1[i - 2] == str2[j - 1]))
{
d[i, j] = Math.Min(d[i, j], d[i - 2, j - 2] + cost);
}
}
}
return d[str1.Length, str2.Length];
}
작동하지 않는 것 같습니다. 어떤 대안?
예외 : System.NotSupportedException는 메시지있어서 'INT32 LevenshteinDistance (선택 System.String, 선택 System.String)'방법 및이 방법을 인식하지 않는 엔티티 = LINQ는 저장소로 번역 할 수없는 사용자 코드에 의해 처리되지 않은이었다 표현. Source = System.Data.Entity
고마워요. 그것은 효과가있다. 감사합니다. –