You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cosmos: Spatial types, functions and spatial indexes #17317
Reacted by Rian Finnegan, Brice Lambson, Olivier Maire, Mark Brown, Clint Singer, paulost, YohanS, George Chondrompilas, Erik O'Leary, Reese Freeman and 2 more
However using this with EF Core + Cosmos throws the following:
Exception has occurred: CLR/System.InvalidOperationException
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll: 'The property 'GeoLocation.Coordinates' could not be mapped, because it is of type 'double[]' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Cosmos.Internal.CosmosModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
The biggest pain point for us is that Azure Search requires that coordinates be serialised as GEOJson, which is just not possible when using EF Core.
In conclusion, it is not possible to use Cosmos, EF Core, and Azure Search with Geo Spacial data :(
The problem with the solution above is that the whole GeoLocation object is actually saved as a string instead of a JSON literal. This means that Cosmos Indexing won't work. Is there a way to use a value converter but the force EF Core to use the converted value verbatim?
@xtellurian this is literally not working! I just tried it with the data explorer. I added the GeoLocation property to a document and then filtered using the query: "WHERE ST_DISTANCE(c.GeoLocation, {"type": "Point", "coordinates":[100.209,-15.86]}) < 40000". No results were provided.
As said by @cwoolum, it cannot work if the GeoJSON object is saved as a serialized string.
This issue is in the Backlog milestone. We have not yet fully planned the next release but we will re-assess the backlog as part of this. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.
Reacted by George Chondrompilas and Tenu Vlad Gabriel
Activity
xtellurian commentedon Sep 26, 2019
I was super stoked to use EF Core with dotnet 3 - but I've run into an issue with GeoJSON and the Cosmos DB database.
The GeoJSON spec says that coordinates must be stored as follows:
{ "type": "Point", "coordinates": [125.6, 10.1] }So I created a C# POCO class like so:
However using this with EF Core + Cosmos throws the following:
The biggest pain point for us is that Azure Search requires that coordinates be serialised as GEOJson, which is just not possible when using EF Core.
In conclusion, it is not possible to use Cosmos, EF Core, and Azure Search with Geo Spacial data :(
bricelam commentedon Sep 26, 2019
@AndriySvyryd Any easy workarounds using NetTopologySuite.IO.GeoJSON?
AndriySvyryd commentedon Sep 26, 2019
Yes, setting up value converters should be enough to get basic functionality.
bricelam commentedon Sep 26, 2019
@xtellurian Does it have to be embedded JSON or will it work as a string containing JSON?
bricelam commentedon Sep 26, 2019
@AndriySvyryd Do we automatically embed JObject properties?
AndriySvyryd commentedon Sep 26, 2019
We don't have any special handling for JObject, but string should work, I'll try it out later
xtellurian commentedon Sep 26, 2019
Thanks for jumping on this to help :)
@bricelam
I tried manually serializing the GeoJSON in CosmosDB and indexing with Azure Search (as below), and the search indexer seems like it works!
{ "GeoLocation": "{ \"type\": \"Point\", \"coordinates\": [100.2093,-15.868]}" }@AndriySvyryd
It sounds like I can use value conversions to serialize/deserialize the GEOJson with the EF CosmosDB provider.
I don't see a need to use NetTopologySuite.IO.GeoJSON ...
bricelam commentedon Sep 26, 2019
lol, using NTS just to serialize points is definitely overkill. It’ll come in handy for more complex spatial scenarios though
cwoolum commentedon Apr 22, 2020
The problem with the solution above is that the whole
GeoLocationobject is actually saved as a string instead of a JSON literal. This means that Cosmos Indexing won't work. Is there a way to use a value converter but the force EF Core to use the converted value verbatim?It should be saved as
AndriySvyryd commentedon Apr 23, 2020
@cwoolum You'd be able to do it when #20584 is implemented.
For now you can modify the underlying JObject directly
cwoolum commentedon Apr 23, 2020
In the short term, I think that by utilizing that with a raw sql command, you could feasibly use
ST_DISTANCEquerying using EF Core and Cosmos.johnn82 commentedon Sep 15, 2021
@xtellurian this is literally not working! I just tried it with the data explorer. I added the GeoLocation property to a document and then filtered using the query: "WHERE ST_DISTANCE(c.GeoLocation, {"type": "Point", "coordinates":[100.209,-15.86]}) < 40000". No results were provided.
As said by @cwoolum, it cannot work if the GeoJSON object is saved as a serialized string.
Does anybody know how to make it works?
xtellurian commentedon Sep 16, 2021
@johnn82 It worked with Azure Search but I never tried using purely Cosmos
WillTheProgrammer commentedon Apr 25, 2022
@xtellurian - please, please, please provide a quick writeup and code sample of how to do this.
georgechond94 commentedon Dec 8, 2023
Hello! Any news on this?
ajcvickers commentedon Dec 11, 2023
This issue is in the Backlog milestone. We have not yet fully planned the next release but we will re-assess the backlog as part of this. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.