簡體   English   中英

Linq中的DocumentDb空間距離返回奇怪的結果

[英]DocumentDb Spatial Distance in Linq returns weird result

當我對兩個點(Microsoft.Azure.Documents.Spatial)做一個documentdb linq距離查詢時,我得到的結果不同。

下面的測試返回一個包含一個LocationDocument的List。 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;
}

這是由於在非EN語言環境設置中構建LINQ to SQL查詢時,DocumentDB SDK中的一個錯誤(現已修復): https//github.com/Azure/azure-documentdb-net/issues/49

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM