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
2010-10-01 15:29:36
this works for %testwords% but not for %test%words% nor for t__tw___s
Stefanvds
2010-10-01 15:31:30
add System.Data.Linq.SqlClient namespace and call SqlMethods.Like method
AEMLoviji
2010-10-01 15:34:11
return my point
AEMLoviji
2010-10-01 15:35:36
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
2010-10-02 05:14:24
+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
2010-10-01 15:35:54
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
2010-10-01 16:05:22