LIKE operator in LINQ

前端 未结 14 1107
一生所求
一生所求 2020-11-27 16:29

Is there any way to compare strings in a C# LINQ expression similar to SQL\'s LIKE operator?

Suppose I have a string list. On this list I want to search

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 17:03

    Regex? no. But for that query you can just use:

     string filter = "BALTIMORE";
     (blah) .Where(row => row.PortName.Contains(filter)) (blah)
    

    If you really want SQL LIKE, you can use System.Data.Linq.SqlClient.SqlMethods.Like(...), which LINQ-to-SQL maps to LIKE in SQL Server.

提交回复
热议问题