當按條件過濾時,我需要獲取元素的索引(位置)。
這是按條件過濾的代碼:
var rank = await _dbContext.VwJobSupplierWithScores
.OrderBy(x => x.CalculatedSpendCurrencyJob)
.FirstOrDefaultAsync(x => x.JobId == jobId && x.SupplierKey == supplierKey);
我需要獲取之前回傳的集合中元素的位置.FirstOrDefaultAsync
我怎樣才能做到這一點?
uj5u.com熱心網友回復:
您可以使用以下內容:
var rankPair = await _dbContext.VwJobSupplierWithScores
.OrderBy(x => x.CalculatedSpendCurrencyJob)
.Select((x, i) => new { item = x, index = i })
.Where(pair => pair.item.JobId == jobId && pair.item.SupplierKey == supplierKey)
.FirstOrDefaultAsync();
var rank = rankPair.item;
int index = rankPair.index;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/476488.html
