0
以下代碼適用於ASP.NET Core使用Microsoft.Azure.DocumentDB.Core
(版本1.2.1)包和LINQ構建針對DocumentDb數據庫的查詢的API。DocumentDb .NET Core SDK - IQueryable.OrderBy生成無效查詢
但是,生成的查詢無效!
public async Task<IEnumerable<T>> QueryAsync
(Expression<Func<T, bool>> predicate, string orderByProperty)
{
client.CreateDocumentQuery<T>(myCollectionUri)
.Where(predicate)
.OrderBy(x => orderByProperty)
.AsDocumentQuery();
/* rest of the code... */
}
// And I call it:
await repository.QueryAsync<Book>(x => x.Author == "Joe", "Price");
// class Book is a POCO with 3 properties: string Title, string Author, and decimal Price
/*
INVALID generated query:
SELECT * FROM root WHERE (root["Author"] = "Joe") ORDER BY "Price"
Correct query:
SELECT * FROM root WHERE (root["Author"] = "Joe") ORDER BY root["Price"]
*/
是否有可能改變這種行爲?
也許通過IQueryable<T>
編寫的擴展方法,並調用它像這樣:
client.CreateDocumentQuery<T>(myCollectionUri)
.Where(predicate)
.DocumentDbOrderBy(orderByProperty) // new extension method
.AsDocumentQuery();
爲什麼你'OrderBy'仍然包含'AuthorId',當你想要它與「價格」一致。而不是擔心生成的查詢,你能建議你是否得到了不正確的結果'Price Asc' –
@MrinalKamboj我根據我的真實情況製作了示例。剛剛編輯了這個問題 – Poulad