-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity Framework Core 3.1 with NetTopologySuite.Geometries.Point: SqlException: The supplied value is not a valid instance of data type geography #19416
Comments
@Ogglas Please post a small, runnable project that reproduces what you are seeing so that we can investigate. |
Hello, we recently came across this issue when we were testing our API with an Android Simulator (AVD). The virtual device has Googleplex's coordinates pre-configured and when our application tried to persist this point to db, the following exception arose:
I have attached a very simple console program that reproduces the problem: |
cc @airbreather (Just FYI. I plan to dig into this and submit a PR to IO.SqlServerBytes if necessary.) |
@ajcvickers @bricelam Do you still need a runnable project from me now that @tmzblue posted one? |
When mapping to a After swapping the two inputs, your program works on my machine. Check the On my home developer instance running 14.0.2027.2, this SRID is missing from that view, so when I try to insert a record with that SRID, I see the same error message that you report. Changing to one of the SRIDs found in that view, the error goes away. |
@airbreather thanks for the explanation, it solved our problem. Thanks a lot. |
@airbreather Thank you very much, worked flawlessly. Wrote an answer about this on SO as well: https://stackoverflow.com/a/59667168/3850405 Long story short is Google Maps API uses
https://developers.google.com/maps/documentation/javascript/markers A bit tricky to project I have verified that it works here: http://epsg.io/transform#s_srs=4326&t_srs=3857&x=13.003725&y=55.604870 Example conversion:
Complete example program: To get it running:
Code:
|
@airbreather thanks |
Saving a
NetTopologySuite.Geometries.Point
causes the exception:According to all documentation it should be X for longitude and Y for latitude so I don't think that is a problem. I tried to reverse the coordinates just in case but I got the same error as you can see in the examples I have tried.
https://docs.microsoft.com/en-us/ef/core/modeling/spatial
Lat = Y Long = X
https://gis.stackexchange.com/a/68856/71364
I can't find out anything obvious that seems wrong. Optionsbuilder is set up, the table is created with Data Type
geography
that worked really well withDbGeography
for Entity Framework 6.There is no specific cases to handle for a single Point either what I can see in documentation for SQL server.
https://docs.microsoft.com/en-us/ef/core/modeling/spatial#sql-server
The coordinates I'm saving is from Google Maps and therefore EPSG 3857 is used.
https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet
Steps to reproduce
Model:
Test code:
Further technical details
EF Core version: 3.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer with Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
Target framework: NET Core 3.1
Operating system: Windows 10 Enterprise
IDE: Visual Studio 2019 16.4.2
Following NuGets are at version 3.1:
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
The text was updated successfully, but these errors were encountered: