There is a request in the MS-SQL environment

select * from myTable where myTable.field like 'tra%ata' 

How to implement this in LINQ?

1 answer 1

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 
  • and regekspy unless it can be used? they will be in sql'nye broadcast? - Grundy
  • Corrected the answer. - andreycha
  • Saw the implementation of the SqlMethods.Like () method but did not understand what you need to connect to C # to use it? - ArtemiyMVC 2:53 pm
  • @ArtemiyMVC read carefully the documentation, everything is written there: Assembly: System.Data.Linq (in System.Data.Linq.dll) - andreycha
  • Hmm, but it seemed to me linq, which then goes to mssql - Grundy