There is a request in the MS-SQL environment
select * from myTable where myTable.field like 'tra%ata'
How to implement this in LINQ?
There is a request in the MS-SQL environment
select * from myTable where myTable.field like 'tra%ata'
How to implement this in LINQ?
In pure LINQ, you must either use a combination of Contains
/ StartsWith
/ EndsWith
, or regexps. In your case, you can do with the following expression:
Where(i => i.field.StartsWith("tra") && i.field.EndsWith("ata"))
If you need it in LINQ2SQL, then use the specialized SqlMethods.Like()
method (but it works only in the context of LINQ2SQL):
from i in db.myTable where SqlMethods.Like(i.field, "tra%ata") select i
Assembly: System.Data.Linq (in System.Data.Linq.dll)
- andreychaSource: https://ru.stackoverflow.com/questions/510470/
All Articles