在Odata V4 API中发布DbGeography数据类型 [英] Post DbGeography data type in odata v4 api
问题描述
我从DbGeography数据类型中收到的是位置信息.
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
}
]
}
我尝试了多个POSTS,但是似乎都没有成功添加DbGeography Point.
I have tried multiple POSTS, but none of them seem to succeed in adding a DbGeography Point.
关于如何执行此操作的任何想法?我尝试添加与返回的内容相同的内容(不起作用),并使用类型+坐标作为属性(如odata标准中所定义.).
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 .
在另一个问题中,我发现了这个从"System.Data.Entity.Spatial.DbGeography"上的"WellKnownValue"获取值时出错,但此解决方案似乎不够.
In another question, i have found this Error getting value from 'WellKnownValue' on 'System.Data.Entity.Spatial.DbGeography , but this solution seems insufficent.
如果我要添加Location:"POINT(lat long)",我可以使用以下方法来生成数据(但我不知道怎么做)
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)
推荐答案
我将经度坐标发送为纬度,然后像这样在服务器端将纬度转换为DbGeography:
I send the coordinates as longitude, latitude then converts to DbGeography at server side like this:
模型
public class MyModel
{
[Required]
public double Longitude { get; set; }
[Required]
public double Latitude { get; set; }
}
控制器
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();
}
这篇关于在Odata V4 API中发布DbGeography数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!