0

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.

Mike
  • 241
  • 1
  • 13
  • `OData` is a protocol, not a library. What library do you use, which version? Are you sure it supports Spatial data in the first place? What does your code do? Do you have a controller or endpoint? Does your action/endpoint return an `IQueryable` or `IEnumerable` ? What does the *query* look like? – Panagiotis Kanavos Oct 26 '21 at 10:19
  • Hi Panagiotis. I am using OData.Core 7.9.3. Yes I am sure it supports spatial data, according to documentation. I have a controller with a IEnumerable Task. I will update the question to include the query now – Mike Oct 26 '21 at 10:44
  • do you mean [Microsoft.AspNetCore.OData](https://www.nuget.org/packages/Microsoft.AspNetCore.OData/8.0.3)? The latest version is 8.0.3. Both the 7.9 and 8.0 versions have quirks. – Panagiotis Kanavos Oct 26 '21 at 10:51
  • The code you posted is registration code, not query code. It should appear only in `Startup.cs`. What does `Model_bs_age_depth` look like? Is there any recursion? And what does the actual query code do? An `IEnumerable` is the *result* of a query, not the query itself. You could use `ToList()` to read all the data and convert it to a list of items. – Panagiotis Kanavos Oct 26 '21 at 10:51
  • I have it in the controller because I have to run a check to see who is logged in via Azure AD, at start up they aren't authenticated. I followed this youtube video to get set up https://www.youtube.com/watch?v=MoDJnEwkYOE&t=1086s&ab_channel=HassanHabib . Model_bs_age_depth contains a list of other postgres column names. I have updated to show. – Mike Oct 26 '21 at 11:05
  • Also noticed that the query is populated with the correct data - so it is at the point of odata taking those values that it isnt working. – Mike Oct 27 '21 at 08:52
  • And yet, the error says there are recursive navigation links.`The depth limit for entries in nested expanded navigation links was reached.`. What does your DbContext and OData model code look like? Have you specified any relations? What does the OData query do? Did you use `$expand` ? – Panagiotis Kanavos Oct 27 '21 at 09:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238595/discussion-between-mike-and-panagiotis-kanavos). – Mike Oct 27 '21 at 11:04

0 Answers0