问题
What i receive from a DbGeography data type is in Location.
{
"@odata.context":"http://subdomain.mydomain.me/odata/$metadata#Pois","value":[
{
"Id":"d57e6603-5530-4457-b041-6398b7182173","Name":"Demo Home","Address":"Zuidstraat 8 8630 Veurne","Location":{
"Geography":{
"CoordinateSystemId":4326,"WellKnownText":"POINT (51.515574 2.025285)","WellKnownBinary":null
}
},"TagId":"ec32e8f3-c0b8-4bcc-af6c-7059b1ef1a65","RouteId":null
}
]
}
I have tried multiple POSTS, but none of them seem to succeed in adding a DbGeography Point.
Any thoughts on how to do this? I have tried adding the same as what is returned ( doesn't work) and using type + coordinates as properties ( as defined in the odata standard .
In another question, i have found this Error getting value from 'WellKnownValue' on 'System.Data.Entity.Spatial.DbGeography , but this solution seems insufficent.
If i'd add Location : "POINT(lat long)" i could use the following method to generate the data ( but i don't know how)
DbGeography.PointFromText(textValue, 4326)
回答1:
I send the coordinates as longitude, latitude then converts to DbGeography at server side like this:
Model
public class MyModel
{
[Required]
public double Longitude { get; set; }
[Required]
public double Latitude { get; set; }
}
Controller
public IHttpActionResult Post(MyModel model)
{
if (!ModelState.IsValid || model == null)
{
// return error
}
var coordinates = DbGeography.FromText($"POINT({model.Longitude} {model.Latitude})");
// save coordinates to database
return Ok();
}
来源:https://stackoverflow.com/questions/33792793/post-dbgeography-data-type-in-odata-v4-api