views:

61

answers:

2

In sql server, we can issue sql to get data like

select * from table where column like '%myword%'
select * from person where Soundex(LastName) =  Soundex('Ann')

what's the linq query to match above sql?

A: 

you may want to use the difference function

http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.difference%28VS.100%29.aspx

you could also create your own

http://blogs.techrepublic.com.com/programming-and-development/?p=656

John Boker
Thank you. As the information said: You cannot call this function directly. This function can only appear within a LINQ to Entities query. I use entity framework as DAL. So how to write it in INQ to Entities query? Say q is EntityQuery<person>, query should be like something as q = q.Where(p => p.LastName.Soundex() == someword);? But I can't do it.
KentZhou
If i were you i'd probably create a stored procedure to do this. I dont know of another way.
John Boker
A: 
from t in table
where t.column.Contains("myword")
select t

In .Net 4.0 you can use the SoundCode function, probably like this:

from p in person
where SqlFunctions.SoundCode(p.LastName) == SqlFunctions.SoundCode('Ann')
select p
Gabe