2010-06-29 85 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));