I'm developing an Web API in ASP.NET Core and we found ourselves in the need of running a background task for a large bulk insert operation. The model I'm inserting however contains a property of the Geometry
type from the .NET Topology Suite.
public class GeometricData
{
//...
public Geometry Geometry { get; set; }
}
In order to bulk insert, I'm following a method I found here and it is quite performatic, but its implementation is beyond the scope of this question. Even though it is fast, an user could be inserting over one million records in one go for instance, so we decided to move this processing to a background task. The Hangfire extension looked like something that could save us a lot of time at first, but it doesn't seem to handle well the Geometry
type. In the code below, the BackgroundTask
method might as well be an empty method:
public Task BulkInsert(IEnumerable<GeometricData> list)
{
BackgroundJob.Enqueue(() => BackgroundTask(list));
return Task.CompletedTask;
}
Just the act of passing a list of Geometry
as a parameter to BackgroundTask
in the action for Enqueue
will throw the unfortunate error:
Self referencing loop detected for property 'CoordinateValue' with type 'NetTopologySuite.Geometries.Coordinate'. Path '[0].Geometry.Coordinates[0]'.
As a matter of fact, Coordinates
(a NTS class) does reference itself:
No idea why they would do that, but they did. Regardless, everything worked just fine up until now, but unless I manage to find a solution to this (or even maybe work my way around it), I'm gonna be in a heap of trouble implementing a background worker from scratch (I'll be using the Worker Service, in case anyone is wondering). Any pointers?