LINQ inserts 'ESCAPE N'~' in query

后端 未结 3 1384
谎友^
谎友^ 2021-01-05 10:33

When I examine the sql query the linq spits out, I noticed that it places a ESCAPE N\'~\' when doing a LIKE command. How do I get rid of this? It seems like the query take

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 11:12

    If you use LINQ 2 Entities, use SqlQuery to remove the "~" character.

    Just append the value to compare like an ordinary sql query.

    For example:

    var resultList = context.TableName.SqlQuery(
                    "SELECT * FROM TableName WHERE field LIKE '%" + fieldValue+ "%' ").ToList();
    

提交回复
热议问题