好的,我使用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());
}
现在,几乎一切看起来都不错。我可以使用OData查询,例如host / Aerodrome?$ filter = startswith(Name,&#39; Flor&#39;)&#34;)或host / Aerodrome?$ top = 20&amp; $ skip = 60&#34;我得到了预期的结果集。
但是,我只能使用geo。*过滤器进行过滤器工作。
host / Aerodrome?$ 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
有人可以启发我做错的事吗?
答案 0 :(得分:0)
在odata V4中未实现地理功能。您可以自己添加支持,但这是一个涉及更改oData代码本身的复杂解决方案。
此处解释了解决方案Dealing with spatial data in OData