2014-02-13 27 views
0

我試圖修改解決方案Search Feature using .Contains with terms within a one field但需要一些幫助。用多個條款使用包含搜索

我有一個對象結構:

public class product 
    { 
     public string productID {get;set;} 
     public List<searchTerms> searchTerms {get; set;} 
    } 

    public class searchTerms 
    { 
     public string searchTerm {get; set;} 
    } 

我想回到一個新的列表,其中SEARCHTERM匹配。我試過了:

matchedProds = (
      from p in prods 
      where p.searchTerms.Contains(term) 
      select p 
      ).ToList(); 

但是不能使它作爲文字字符串或作爲searchTerm使用。

我哪裏錯了?

感謝

回答

0

使用Any

var matchedProds = (
     from p in prods 
     where p.searchTerms.Any(st => st.searchTerm == term) 
     select p 
     ).ToList(); 
1

什麼:

var products = allProducts.Where(m => m.searchTerms.Any(n => n.searchTerm == input)).ToList()