views:

68

answers:

2

SELECT * FROM Customer WHERE Name 'LIKE [a-f]%'

How Can I acheive this in Linq??

In other words in linq how can i select all Names between a and f??

Thanks,

A: 

You could use C# Regex class to match records:

var selectedCustomers = from customer in customers
               where Regex.Match(customer.Name, "^[a-f].*$").Success
               select customer;
Russell
That cannot be tanslated into a SQL query by LINQ to SQL
SLaks
+7  A: 

There's a helper class called SqlMethods in the System.Data.Linq.SqlClient namespace that provides a Like method that emulates the SQL LIKE statement.

Your query would be:

var query = from c in Customers
            where SqlMethods.Like(c.Name, "[a-f]%")
            select c;
Mircea Grelus
+1, great find.
Winston Smith