Could anyone help me with something I have been stuck on for a few days now. I am using Odata with asp.net core and NetTopologySuite.
I have a postgres database with column type Geometry. The request with npgsql works fine but the serialization by Odata is a mess.
It seems that odata is looping. I should only receive one XYZ per returned item.
Any suggestions?
This is what is returned.
,"shape":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","SRID":4326,"Coordinates":[{"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":{"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":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue":{"X":-9.129147,"Y":41.133908999999996,"Z":"NaN","M":"NaN","CoordinateValue": Blockquote
Model
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; }
}
}
Controller
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;
}
Storage Broker
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; }
}
}
Debug showing query
Blockquote Entity Framework Core 3.1.20 initialized 'StorageBroker' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: using NetTopologySuite info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (39ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT b.age_depth_id, b.age_epoch_top, b.age_ma, b.age_period_base, b.age_period_top, b.age_stage_base, b.basin_id, b.basin_name, b.boundary, b.country, b.depth, b.depth_f, b.field_id, b.field_name, b.interpretation_version, b.latitude, b.lithostrat_formation, b.lithostrat_group, b.lithostrat_member, b.location, b.longitude, b.product_id, b.product_title, b.product_year, b.province_state, b.region_id, b.region_name, b.shape, b.site_id, b.site_name, b.site_type, b.table_meta_id, b.tvd_base, b.tvd_base_f, b.tvd_top, b.tvd_top_f FROM bs_age_depth AS b fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. Microsoft.OData.ODataException: The depth limit for entries in nested expanded navigation links was reached. The number of nested expanded entries cannot exceed 100.