Check if a String value contains any number by using Lambda Expression

Viewed 6242

I have a SQL query that retrieves only the names not containing any number:

...
WHERE Name NOT LIKE '%[0-9]%'

On the other hand, when trying to use this query in Lambda Expression with different combinations as shown below, none of them is working does not work:

.Where(m => !m.EmployeeName.Contains("%[0-9]%")

or

 .Where(m => !m.EmployeeName.Contains(".*[0-9].*")

How can I use NOT LIKE method in Lambda Expression?

Update: My lambda expression is shown below:

return Json(db.TEmployees
    .Where(m => m.Status == Enums.Status.Active)
    .AsEnumerable()
    .Where(m => !Regex.IsMatch(m.EmployeeName, ".*[0-9].*"))
    .Select(m => new { ID = m.EmployeeID, EmployeeName = m.EmployeeName }), 
        JsonRequestBehavior.AllowGet);

6 Answers
Related