我不知道linq AT ALL。做所有後端工作的人已經停留了2周,但我需要做的是根據「term」過濾getItemList。我試圖尋找如何添加「where」子句,但我只是沒有運氣。將「Where」添加到linq語句中?
請注意,我在getItemList參數中添加了「字符串項」。
請幫忙。
public IndexedItem getItem(string name) {
var repo = new Project.SQLServerDataManager.IndexItemRepository(ConfigurationManager.ConnectionStrings["ItemRepositoryConnstring"].ConnectionString);
return repo.getItem(name);
}
public object getItemList(string term) {
var repo = getRepo();
return from i in repo.getItem()
select new { name = i.name, itemType = i.itemType.name };
}
private IIndexedItemReadOnlyRepository getRepo() {
return new Project.SQLServerDataManager.IndexItemRepository(ConfigurationManager.ConnectionStrings["ItemRepositoryConnstring"].ConnectionString);
}
編輯澄清: 「術語」 是搜索詞。它需要匹配項目「名稱」
HTTP: //code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b是一個非常好的地方,您可以查看各種LINQ查詢的簡單示例。 – SamiHuutoniemi
感謝您的入門... –