LIKE query with Entity Framework [duplicate]

喜欢而已 提交于 2019-11-30 05:39:48
MethodMan

Would something like this 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

Andrew Cooper
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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!