tags:

views:

50

answers:

4

I know how to use .Contains for looking up '%testwords%', my question is about how to use linq to get '%test%words%'. Thanks

A: 

yes you can use .Where(oh => oh.Hierarchy.Contains("testwords")) syntax too. But if you want to do it with LINQ then write this code

var query = from c in ctx.Customers
        where SqlMethods.Like(c.City, "%test%words%")
        select c;
AEMLoviji
this works for %testwords% but not for %test%words% nor for t__tw___s
Stefanvds
add System.Data.Linq.SqlClient namespace and call SqlMethods.Like method
AEMLoviji
return my point
AEMLoviji
+1  A: 
.Where(q => SqlMethods.Like(q,"%test%words%"))

use SqlMethods

Stefanvds
how about the % in the middle?
DOK
Thanks, Stefanvds. We are not allowed to use linq to sql
Zalan
it is not meaning that it is not correct answer. You cna change Linq To Sql syntax to LINQ. It s not difficult. "Your code is correct Stefandvds"
AEMLoviji
+2  A: 

maybe something like this if you're not using Linq to SQL:

var query = from o in yourObject
            where  o.field.Contains("test")
            where o.field.Contains("words")
            where o.field.indexOf("test") < o.field.indexOf("words")
            select o;

if you are using Linq to SQL, use the SqlMethods that Stefanvds showed.

Chris Conway
this is the answer then
Zalan
A: 

well, i think the answer is NO :(

Probably the closest answer is lst.Where(foo.Contains("test") && foo.Contains("word")), though that statement doesnt give the right sequence as '%test%word%'

Zalan