當我在兩個Points(Microsoft.Azure.Documents.Spatial)上執行documentdb linq distance查詢時,我得到不同的結果。DocumentDb Linq中的空間距離返回奇怪的結果
下面的測試返回一個包含一個LocationDocument的列表。 test2返回一個空列表。 isEqual bool返回true,所以我不能理解他們爲什麼返回不同的結果。我有手動確認經度和緯度也是一樣的。
// one document
var test = MyCollectionRepository<LocationDocument>
.GetItems(x => x.Point.Distance(x.Point) < radius)
.ToList();
// no documents
var test2 = MyCollectionRepository<LocationDocumentDocument>
.GetItems(x => x.Point.Distance(point) < radius)
.ToList();
// true
bool isEqual = point.Equals(test[0].Point);
這裏是GetItems()方法從資源庫中調用:
public static IReadOnlyCollection<T> GetItems(Expression<Func<T, bool>> predicate)
{
var items = Client.CreateDocumentQuery<T>(Collection.DocumentsLink)
.Where(predicate)
.ToList();
return items;
}
有誰知道爲什麼發生這種情況?它不是調試的最簡單的事情,因爲距離調用僅在作爲documentdb中的查詢運行時可用。
在此先感謝。
點對象:
point.Position.Latitude.ToString(); //18.4239
test[0].Point.Position.Latitude.ToString(); //18.4239
point.Position.Longitude.ToString(); //-33.9253
test[0].Position.Longitude.ToString(); //-33.9253
編輯:
我已經更新到Microsoft.Azure.DocumentDB庫(1.4.1)的最新版本,問題發生了變化。正如評論中提到的那樣,這個問題似乎與我的CultureInfo設置有關。我在非美國文化(準確地說en-ZA)。
test2然後拋出一個異常,而test1仍然輸出預期的結果。我得到一個AggregateException。然後,我只需將查詢中的啓用掃描添加到標題。以下是如何做到這一點:
public static IReadOnlyCollection<T> GetItems(Expression<Func<T, bool>> predicate)
{
var items = Client.CreateDocumentQuery<T>(Collection.DocumentsLink, new FeedOptions { EnableScanInQuery = true })
.Where(predicate)
.ToList();
return items;
}
我無法用這些數據重現此問題。你能否包括半徑值?活動ID也有幫助。 –
這是由於DocumentDB SDK在構建非EN語言環境設置中的LINQ to SQL查詢中的一個錯誤:https://github.com/Azure/azure-documentdb-net/issues/49。很快就會修復。 –
我們相信我們已經解決了這個問題,但想確認一下。你能提供一個repro項目嗎?你是否使用CultureInfo運行而不是en-US或甚至en-ZA(因爲我看到你來自Kaapstad) –