1

I am getting the following error when updating a database with default point data:

System.ArgumentException: 24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view.

My model:

public class Venue
{
    public Point Location { get; set; }
}

My default data:

internal class VenueConfiguration : IEntityTypeConfiguration<Venue>
{
    public void Configure(EntityTypeBuilder<Venue> builder)
    {
        builder.HasData(
            new Venue
            {
                Location = new Point(19.072506, 47.525198) { SRID = 4326 }
            }
        );
    }
}

When updating the database, I see

Failed executing DbCommand (37ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Location') AND [object_id] = OBJECT_ID(N'[Venues]'))
    SET IDENTITY_INSERT [Venues] ON;
INSERT INTO [Venues] ([Location])
VALUES (geography::STGeomFromText('POINT (47.525198 19.072506)', 0));
IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Location') AND [object_id] = OBJECT_ID(N'[Venues]'))
    SET IDENTITY_INSERT [Venues] OFF;

It seems the SRID is not applied when updating the database. How can I cope with this issue?

I even tried with GeometryFactory as well.

internal class GeometryHelper
{
    public static GeometryFactory GeometryFactory { get; set; }
        = NtsGeometryServices.Instance.CreateGeometryFactory(4326);
}
Location = GeometryHelper.GeometryFactory.CreatePoint(new Coordinate(19.072506, 47.525198))

The result is the same.

AnotherNewbie
  • 198
  • 1
  • 1
  • 6
  • This looks like a bug. Can you [submit a new issue](https://github.com/dotnet/efcore/issues/new/choose)? – bricelam Jul 20 '23 at 16:07

0 Answers0