public override bool Equals(object obj) { SearchResult test = new SearchResult(); try { test = (SearchResult) obj; } catch (Exception) { return false; } return this.ChineseId == test.ChineseId; }
//todo: this is the problem right here for the displaying slow. Too many queries private List<SearchResult> CreateSearchResultsFromEnglishesandChinese(List<English> englishDefinitions, List<Chinese> chineses) { var dictionarySearchResults = from english in englishDefinitions join chinese in chineses on english.ChineseId equals chinese.ID orderby chinese.ID select new DictionarySearchResult(chinese.ID, chinese.Traditional, chinese.Simplified, chinese.Pinyin, english.Definition); SearchResult searchResult = new SearchResult(); List<SearchResult> results = new List<SearchResult>(); List<int> dictionaryIds = new List<int>(); results.Add(searchResult); int searchResultsAddIndex = 0; foreach (DictionarySearchResult dictionarySearchResult in dictionarySearchResults) { if (dictionarySearchResult.ChineseID != results[searchResultsAddIndex].ChineseId) { searchResult = new SearchResult { ChineseId = dictionarySearchResult.ChineseID, Pinyin = dictionarySearchResult.Pinyin, Traditional = dictionarySearchResult.Traditional, Simplified = dictionarySearchResult.Simplified, Definitions = new List<string>() }; searchResult.Definitions.Add(dictionarySearchResult.Definition); results.Add(searchResult); searchResultsAddIndex++; } else { results[searchResultsAddIndex].Definitions.Add(dictionarySearchResult.Definition); } } results.RemoveAt(0); results = results.OrderBy(x => x.Pinyin.Length).ToList(); return results; }