1

What will be the LINQ equivalent of this cosmos SQL API query:

SELECT c as Person, ST_DISTANCE(c.location, {'type': 'Point', 'coordinates':[-122.3382419, 47.6074856]}) as Distance
FROM c 
WHERE  c.DocType = 0 AND 
ST_DISTANCE(c.location, {'type': 'Point', 'coordinates':[-123.3382419, 47.6074856]}) < 1 AND NOT c.Blocked

which gets back

[
    {
        "Person": {
            "DocType": 0,
            "location": {
                "type": "Point",
                "coordinates": [
                    -123.3382419,
                    47.6074856
                ]
            },
            "MDS": "Chwal",
            "Description": "Bduwhs",
            "Contents": null,
            "GFree": false,
            "Veg": false,
            "AllergicContents": null,
            "Calorie": 0,
            "LinkToRecipe": null,
            "Cost": 36,
            "DASD": "Mexican",
            "ExpirationTime": "2019-12-17T11:30:52Z",
            "Images": [
                "test/25254932-2898-5fd7-949b-b2feb25a4964"
            ],
            "ProducerUserId": "1b36c0f1-425c-483a-bb01-69b06e69f203",
            "ExchangeDateTimeStartInUtc": "2019-12-17T20:30:52Z",
            "ExchangeDateTimeEndInUtc": "2019-12-17T19:30:52Z",
            "Blocked": false,
            "id": "asd,
            "_rid": "asd=="

        },
        "Distance": 0.1
    }
]

The problem with ST_DISTANCE is that it can only be calculated on Cosmos db, and can't be post evaluated.

1

1 Answer 1

0

Found a way to do it other than writing SQL query string

DocumentDBRepository.RunQueryAsync(
from c in DocumentDBRepository.DocumentQuery<Person>()
where c.DocType == 0
&& c.Location.Distance(point) < 1
&& !c.Blocked
select new { Person = c, Distance = c.Location.Distance(point) });

Also realized that LINQ lambda is different from a LINQ query. The above is a LINQ query, A LINQ lambda looks like this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.