I am using Entity Framework Core 2.2 with NetTopologySuite 1.15.1 and SQL Server 2016. Having a column of type IPoint
works great to the point I want to create an index on it.
I have this table
public class Location
{
public int Id { get; set; }
public IPoint Coordinates { get; set; }
public static void Register(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Location>(entity => entity.HasIndex(x => new {x.Coordinates}));
}
}
And EF core handles it well while generating a migration thus producing the following code:
migrationBuilder.CreateIndex(
name: "IX_Locations_Coordinates",
schema: "data",
table: "Locations",
column: "Coordinates");
However, as soon as I try to apply the migration to database, SqlException
is thrown with the following message
SqlException: Column 'Coordinates' in table 'data.Locations' is of a type that is invalid for use as a key column in an index or statistics.
SQL Server does support indexes on columns of type geography
.
I believe the reason might be that EF Core is trying to create a regular index rather than spatial one.
Am I doing something wrong or it's just not supported? Is there a way to tell EF Core that it should create spatial index?