Linq query using contains is not working

前端 未结 1 1248
生来不讨喜
生来不讨喜 2021-01-22 15:25

I would like to use a query in LINQ and use a function that works like \"LIKE\" in TSQL. For example:

 SELECT salary 
 FROM employees 
 WHERE last_name LIKE \'R%         


        
相关标签:
1条回答
  • 2021-01-22 16:10

    Contains should work as it checks for a substring. It is equal to executing the sql statement where BI_FORMAT_NAME LIKE '%Tom%'

    But if need records for LIKE 'Tom%' condition, You may use StartsWith method.

    where  P.BI_FORMAT_NAME.StartsWith("Tom")
    

    It should work as long as your LINQ query without the where clause is returning records with BI_FORMAT_NAME column has values like "Tom" or "TomSomeThingElse"

    The LINQ methods for different SQL likeclause use cases are

    1. LIKE '%To%' --> Contains("To")
    2. LIKE 'Tom%' --> StartsWith("Tom")
    3. LIKE '%Tom' --> EndsWith("Tom")
    0 讨论(0)
提交回复
热议问题