下面是有問題的代碼段。我們正在嘗試將項目與項目屬性集合進行匹配。下面的代碼工作,我們返回我們需要的,但它很慢。我們很好奇最好的辦法是做什麼。任何幫助是極大的讚賞。我們也對SQL中的選項開放。謝謝!獲得快速匹配的所有項目的最佳方式
var items = await GetItemsAsync(repository, a, b);
// Next we need to get all of the properties for those items.
var results = new List<Result>();
foreach(var c in items)
{
c.Properties = await GetItemProperties(repository, c.Id);
var matchedProperties = selectedProperties.Where(si => c.Properties.Any(i => i.Id == si.Id));
if(matchedProperties.Count() > 0)
{
results.Add(new Result(c)
{
MatchedProperties = matchedProperties,
Relevance = (decimal)matchedProperties.Count()/(decimal)selectedProperties.Count()
});
}
}
你的代碼的一部分,是exaclty慢GetItemsAsync或GetItemProperties或者在selectedProperties.since我們不知道的是裏面有什麼代碼的methods.it的努力幫助?我唯一可以說的就是int selectedProperties.Count()強制轉換十進制一次。 – Arash
也許想想掩飾。 – SimpleVar