Like operator or using wildcards in LINQ to Entities

前端 未结 6 1337
抹茶落季
抹茶落季 2021-02-06 05:12

I\'m using LINQ 2 Entities. Following is the problem:

string str = \'%test%.doc%\' 
.Contains(str) // converts this into LIKE \'%~%test~%.doc~%%\'
6条回答
  •  日久生厌
    2021-02-06 05:34

    The SQL method PATINDEX provides the same functionality as LIKE. Therefore, you can use the SqlFunctions.PatIndex method:

    .Where(x => SqlFunctions.PatIndex("%test%.doc%", x.MySearchField) > 0)
    

提交回复
热议问题