Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ version of SQL's LIKE statement

Tags:

sql

linq

I'm new at LINQ, searching the net for LINQ samples that mimic SQL's LIKE statement doesn't satisfy myself.

What I want is producing the same query result as this SQL

SELECT * FROM table_1 WHERE column_1 LIKE '__0%'

I want to query from table_1 where column_1's third character is '0'

Is there equivalent statement in LINQ

:D thank you

like image 859
strike_noir Avatar asked Mar 29 '10 09:03

strike_noir


2 Answers

You can use the SqlMethods class. It's part of System.Data.Linq (a.k.a. LINQ to SQL).

from item in db.Table1
where SqlMethods.Like(item.Column1, "__0%")
select item;
like image 94
Steven Avatar answered Nov 20 '22 16:11

Steven


Likes are produced by following methods: StartsWith, EndsWith and Contains. Try to play with them.

like image 9
Andrey Avatar answered Nov 20 '22 16:11

Andrey