tags:

views:

57

answers:

2

I have list of words. I type in a word misspelled. Can I query the list using linq to get words that sounds like (soundex) the misspelled word?

+2  A: 

I believe you can.

A quick google search came up with this link:

Code Snippet

from elt in SomeTable.AsEnumerable()

where SoundEx(elt.SomeWordsSoundExCode) == SoundEx("MyWord")

select elt;
CrimsonX
this is for linq to sql not linq to objects?
zachary
A: 

If you want to use LINQ to SQL to query database, then you'll probably want to run the comparison on SQL side. You could use AsEnumerable, but then you'll need to implement the algorithm in C# and process the data in-memory.

I believe that LINQ to SQL doesn't provide any built-in method that would be translated to a call to the SOUNDEX function in SQL. However, you can add mapping for a user-defined SQL function (See for example this article). So, you could define your SQL function that performs the comparison and then write something like:

var db = new MyDatabaseContext();
var q = from w in db.Products
        where db.SimilarSoundEx(w.Name, searchInput)
        select w;
Tomas Petricek