Software Development Network>> Visual Studio>> Using "Like" in LINQ
YES, if you want to use it as part of your integrated query; but it does not work with WildCard caharacters.
For example- create a console application and use the following piece of code:
Module Module1
Sub Main()
Dim somename = {"vidya", "video", "vaidya"}
Dim name = From n In somename _
Where n Like "vidya" _
Select n
Console.WriteLine("Names are as follows: ")
For Each Dim m In name
Console.Write(m & " ")
Next
Console.ReadLine()
End Sub
End Module
This shows that Like operator works but does not support the wildcards as of now.
For LINQ queries, you could use a regular expression. For example, you can do the following:
Imports System.IOImports System.Text.RegularExpressions
dim KBFiles = From f in Directory.GetFiles("C:\Windows") _ Where Regex.IsMatch(f,"KB[0-9]{6}.log") Select F
Jim Wooleyhttp://devauthority.com/blogs/jwooley/default.aspx
In our NPersist version ov linq we simpy made an extension method for system.string
where n.Like("%hello%") select n
we also added a .Soundex method (there is a working soundex implementation on codeproject.com)
so we can also do:
where n.Soundex() == "Johansson".Soundex()
//Roger
Using "Like" in LINQ
Andrew MacNeill
from customer in db.GetTable<Customer>()
where customer.City.Contains("ari")
select customer;
zuninet
YES, if you want to use it as part of your integrated query; but it does not work with WildCard caharacters.
For example- create a console application and use the following piece of code:
Module Module1
Sub Main()
Dim somename = {"vidya", "video", "vaidya"}
Dim name = From n In somename _
Where n Like "vidya" _
Select n
Console.WriteLine("Names are as follows: ")
For Each Dim m In name
Console.Write(m & " ")
Next
Console.ReadLine()
End Sub
End Module
This shows that Like operator works but does not support the wildcards as of now.
DLeighty
For LINQ queries, you could use a regular expression. For example, you can do the following:
Imports System.IO
Imports System.Text.RegularExpressions
dim KBFiles = From f in Directory.GetFiles("C:\Windows") _
Where Regex.IsMatch(f,"KB[0-9]{6}.log")
Select F
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Spidey
In our NPersist version ov linq we simpy made an extension method for system.string
where
n.Like("%hello%")
select n
we also added a .Soundex method (there is a working soundex implementation on codeproject.com)
so we can also do:
where
n.Soundex() == "Johansson".Soundex()
//Roger