程序代码
代码如下 |
复制代码 |
//like 'zhang%'
var data = context.People.Where(person => person.Name.StartsWith("zhang"));
//like '%zhang'
var data = context.People.Where(person => person.Name.EndsWith("zhang"));
//like '%yuan%'
var data = context.People.Where(person => person.Name.IndexOf("yuan") != -1);
|
System.Data.Linq.SqlClient命名空间下的SqlMethods.Like方法可以实现一样功能,但仅在Linq to SQL可以使用,LINQ to Entities不支持。