任何人都可以帮助我解决我已经坚持了几天的事情。我将 Odata 与 asp.net 核心和 NetTopologySuite 一起使用。
我有一个列类型为 Geometry 的 postgres 数据库。使用 npgsql 的请求工作正常,但 Odata 的序列化是一团糟。
似乎 odata 正在循环。每个退回的物品我应该只收到一个 XYZ。
有什么建议么?
这就是返回的内容。
,"形状":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","SRID":4326,"坐标":[{"X" :-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","坐标值":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN ","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{" X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z": "南","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{"X" :-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","坐标值":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN ","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{" X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":块引用
模型
public class Model_bs_age_depth {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string age_depth_id { get; set; }
public string site_id { get; set; }
public string site_type { get; set; }
public string site_name { get; set; }
public decimal? latitude { get; set; }
public decimal? longitude { get; set; }
public string country { get; set; }
public NetTopologySuite.Geometries.Point shape { get; set; }
}
}
控制器
public async Task<ActionResult<IEnumerable<Model_bs_age_depth>>> Getbs_age_depth() {
var optionsBuilder = new DbContextOptionsBuilder<StorageBroker>()
.UseNpgsql(_connectionString, x =>
x.UseNetTopologySuite())
.UseLoggerFactory(factoryLogger)
.Options;
StorageBroker context = new StorageBroker(optionsBuilder);
var query = await context.bs_age_depth.ToListAsync();
if (query == null) {
}
return query;
}
存储代理
public class StorageBroker : DbContext {
private static readonly ILoggerFactory factoryLogger = LoggerFactory.Create(builder => builder.AddConsole())!;
public StorageBroker(DbContextOptions<StorageBroker> options)
: base(options) {
}
public DbSet<Model_bs_age_depth> bs_age_depth { get; set; }
public DbSet<bs_biozone> bs_biozone { get; set; }
public DbSet<DBModel> cd_site { get; set; }
}
}
调试显示查询
tvd_top_f FROM bs_age_depth AS b 失败:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] 执行请求时发生未处理的异常。Microsoft.OData.ODataException:已达到嵌套展开导航链接中条目的深度限制。嵌套展开条目的数量不能超过 100。