2010-06-29 78 views

回答

11

使用正常的.NET方法。例如:(或者EndsWith,或Contains

var query = from person in people 
      where person.Name.StartsWith("apple") // equivalent to LIKE 'apple%' 
      select person; 

的LINQ to SQL将转化到这些相应的SQL。

这将在点标记以及工作 - 没有什么神奇的有关查询表达式:

// Will find New York 
var query = cities.Where(city => city.Name.EndsWith("York")); 
0

name.contains( “苹果”);

5

你需要StartsWithContainsEndsWith取决于您的字符串可能会出现使用。例如:

var query = from c in ctx.Customers 
      where c.City.StartsWith("Lo") 
      select c; 

将查找以“Lo”开头的所有城市(例如伦敦)。

var query = from c in ctx.Customers 
      where c.City.Contains("York") 
      select c; 

会发现,含有 “约克” 所有城市(如纽约,约克镇)

Source

0

我用item.Contains( “标准”),但是,它的工作效率只有你转换为更低,标准和这样的项目:

string criteria = txtSearchItemCriteria.Text.ToLower(); 

IEnumerable<Item> result = items.Where(x => x.Name.ToLower().Contains(criteria));