简体   繁体   English

Azure 移动应用服务器在 GET 上不返回 DBGeography

[英]Azure Mobile App Server doesn't return DBGeography on GET

My instance of Microsoft Azure Mobile App Server will happily store a DBGeography POINT() as a table column, which is contained in the JSON data confirming that a POST has been made.我的 Microsoft Azure 移动应用服务器实例将愉快地将 DBGeography POINT() 存储为表列,该列包含在 JSON 数据中,确认已进行 POST。

My 'Location' data object:我的“位置”数据 object:

public DbGeography Location { get; set; }

    [NotMapped]
    public double Longitude { get; set; }
    [NotMapped]
    public double Latitude { get; set; }

My controller:我的 controller:

public async Task<IHttpActionResult> PostI4Item([FromBody] IslandFourEntity item)
    {
        var coordinates = DbGeography.FromText($"POINT({item.Longitude} {item.Latitude})");
        item.Location = coordinates;
        
        IslandFourEntity current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }

Postman response after 'POST' request: “POST”请求后的 Postman 响应:

{
"body": "Test body value",
"subject": "Test subject value",
"type": "type",
"location": {
    "geography": {
        "coordinateSystemId": 4326,
        "wellKnownText": "POINT (172.590401 -43.539994)"
    }
},
"longitude": 172.590401,
"latitude": -43.539994,
"id": "58542f5ee84d4867ae1f3d2c3b098b1b",
"version": "AAAAAAAAD6I=",
"createdAt": "2021-03-05T00:16:12.292Z",
"updatedAt": "2021-03-05T00:16:12.731Z",
"deleted": false

} }

However if you GET all table values, or just one individual item, the column containing the DBGeography item isn't contained within (despite definitely being saved in the database.)但是,如果您获取所有表值或仅一个单独的项目,则包含 DBGeography 项目的列不包含在其中(尽管肯定保存在数据库中。)

Default GET response for that record:该记录的默认 GET 响应:

{
"deleted": false,
"updatedAt": "2021-03-05T00:16:12.731Z",
"createdAt": "2021-03-05T00:16:12.292Z",
"version": "AAAAAAAAD6I=",
"id": "58542f5ee84d4867ae1f3d2c3b098b1b",
"type": "type",
"subject": "Test subject value",
"body": "Test body value"

} }

As you can see, every other column was returned except for 'Location'.如您所见,除了“位置”之外,所有其他列都已返回。

So this question is probably more for anyone who has had experience with Microsoft Azure Mobile App Services, but how can you modify the default Query() method to serialise DBGeography into a string?所以这个问题对于任何有过 Microsoft Azure 移动应用服务经验的人来说可能更多,但是如何修改默认的 Query() 方法以将 DBGeography 序列化为字符串?

Ultimately, you get an IQueryable<T> back and then it is serialized by the ASP.NET OData (v3) system or the Node.js system (you don't say which you are using).最终,你得到一个IQueryable<T> ,然后它被 ASP.NET OData (v3) 系统或 Node.js 系统序列化(你没有说你正在使用哪个)。 There are two issues here - what the IQueryable is returning, and what oData does with it.这里有两个问题 - IQueryable 返回什么,以及 oData 用它做什么。

Since it is an OData v3 endpoint, try adding ?$expand=location to see if that will expand the output.由于它是 OData v3 端点,请尝试添加?$expand=location以查看是否会扩展 output。 Read up on the $expand option in the docs - section 5.1.3 covers $expand.阅读文档中的 $expand 选项 - 第 5.1.3 节涵盖了 $expand。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM