gpt4 book ai didi

entity-framework - 使用 $filter=geo.distance 对 DbGeometry 属性进行 OData 查询

转载 作者:行者123 更新时间:2023-12-03 17:48:50 27 4
gpt4 key购买 nike

好的,我正在使用 OData v4 和 WebApi 2.2,其中一些实体在坐标系 4674 中设置了 DbGeometry 属性。
假设我们有一个简单的实体,如下所示:

public class Aerodrome
{
public short Id { get; set; }
public string Name { get; set; }
public System.Data.Entity.Spatial.DbGeometry Location { get; set; }
}

和一个简单的 ODataController 如下:
public class AerodromeController : ODataController
{

private SqlDbContext Db

protected override void Initialize(HttpControllerContext controllerContext)
{
Db = new SqlDbContext();
base.Initialize(controllerContext);
}

[EnableQuery]
public IQueryable<Aerodrome> Get()
{
return Db.Aerodrome;
}

protected override void Dispose(bool disposing)
{
Store.Dispose();
base.Dispose(disposing);
}
}

}

而 WebApiConfig 设置成这样
public static void Register(HttpConfiguration config)
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Aerodrome>("Aerodrome");
config.MapODataServiceRoute("odata", null, builder.GetEdmModel());
}

现在,几乎一切都看起来不错。我可以使用像 host/Aerodrome?$filter=startswith(Name, 'Flor')") 或 host/Aerodrome?$top=20&$skip=60"这样的 OData 查询,我得到了预期的结果集。

但是,我只能使过滤器与 geo.* 过滤器一起工作。

主机/机场?$filter=geo.distance(Location, POINT (-72.768952 -7.599057)) lt 900.0

它返回错误如下:
"error":{
"code":"","message":"The query specified in the URI is not valid. ')' or ',' expected at position 59 in 'geo.distance(Localizacao,geography, Point(-122.03547668457 47.6316604614258)) lt 900'.","innererror":{
"message":"')' or ',' expected at position 59 in 'geo.distance(Localizacao,geography, Point(-122.03547668457 47.6316604614258)) lt 900'.","type":"Microsoft.OData.Core.ODataException","stacktrace":" em Microsoft.OData.Core.UriParser.Parsers.FunctionCallParser.ParseArgumentList()\r\n

有人可以启发我做错了什么吗?

最佳答案

odata V4 中未实现地理功能。您可以自己添加支持,但这是一个有点复杂的解决方案,涉及更改 oData 代码本身。

解决方法在这里解释Dealing with spatial data in OData

关于entity-framework - 使用 $filter=geo.distance 对 DbGeometry 属性进行 OData 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26059392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com