Linq is equivalent to SQL LIKE [af]

SELECT * FROM Customer WHERE Name 'LIKE [af]%'

How can I achieve this in Linq?

In other words, in linq, how can I select all the names between a and f?

Thanks,

+3
source share
2 answers

The class System.Data.Linq.SqlClienthas a helper class called SqlMethods , which provides a method Likethat emulates the SQL LIKE statement.

Your request:

var query = from c in Customers
            where SqlMethods.Like(c.Name, "[a-f]%")
            select c;
+8
source

You can use the C # Regex class to map entries:

var selectedCustomers = from customer in customers
               where Regex.Match(customer.Name, "^[a-f].*$").Success
               select customer;
+1
source

Source: https://habr.com/ru/post/1720247/


All Articles