Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIKE query with Entity Framework [duplicate]

Would something like this linq query work for you.. ?

var matches = from m in db.Customers
    where m.Name.Contains(key)      
    select m;

this should also work I edited my answer.

Contains is mapped to LIKE '%@p0%' which is case insensitive


var matches = from m in db.Customers     
    where m.Name.StartsWith(key)
    select m;

Make the search and compare whether the string is either lowercase or uppercase to get the best result since C# is case-sensitive.

var matches = from m in db.Customers     
    where m.Name.ToLower().StartsWith(key.ToLower())
    select m;