如何使用 Cosmos DB 中的 IQueryable 按多列排序?
我嘗試執行以下操作:
books.OrderBy(book => book.Author).ThenBy(book => book.Name);
它適用于 Cosmos DB 模擬器,但不適用于真正的 DB。為什么?
這是我得到的錯誤:
The order by query does not have a corresponding composite index that it can be served from.
uj5u.com熱心網友回復:
這不是您的 C# 代碼的問題。如果要ORDER BY在需要索引的屬性上使用該屬性。對于多列,它是相同的,盡管您需要為ORDER BY子句中以完全相同的順序出現的所有屬性的復合索引。
對于您的用例,您需要將以下索引添加到 Cosmos DB 容器中:
"compositeIndexes": [
[
{
"path": "/Author",
"order": "ascending"
},
{
"path": "/Name",
"order": "ascending"
}
]
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/369449.html
