In SQL i can do something like this :
select * from Table1 whe开发者_Python百科re Col1 like '%'
I'm trying to this in linq like this :
from p in Table1
where SqlMethods.Like(p.Col1, "%")
select new { p.Col1}
But it's not working because it's expecting Col1 to be int.
The reason i'm doing this is because i'm trying to build a search form and must use wildcards for the parameters that aren't completed (some are strings, some are numeric).
How about, for integer values, you specify a range and a predicate that specifies the value must be greater than minimum/less than maximum instead? This seems more intuitive to me than doing a string comparison on a numeric field.
Why not try converting to string then?
from p in Table1
where SqlMethods.Like(p.Col1.ToString(), "%")
select new { p.Col1}
Hm. Like this?
from p in Table1
where p.Col1.ToString().Contains("foo")
select new { p.Col1}
Exchange Contains with BeginsWith/StartsWith as the LIKE functionality can... or use RegExp if it's a more complex expression.
精彩评论