9

我将Entity Framework Core 2.2NetTopologySuite 1.15.1SQL Server 2016一起使用。拥有一列类型IPoint非常有用,以至于我想在其上创建索引。

我有这张桌子

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}));
    }
}

EF 核心在生成迁移时很好地处理它,从而生成以下代码:

migrationBuilder.CreateIndex(
    name: "IX_Locations_Coordinates",
    schema: "data",
    table: "Locations",
    column: "Coordinates");

但是,一旦我尝试将迁移应用到数据库,SqlException就会抛出以下消息

SqlException:表 'data.Locations' 中的列 'Coordinates' 的类型对于用作索引或统计信息中的键列无效。

SQL Server确实支持类型列的索引geography

我相信原因可能是 EF Core 试图创建一个常规索引而不是空间索引。

我做错了什么还是不支持?有没有办法告诉 EF Core 它应该创建空间索引?

4

1 回答 1

10

查看 EF Core 的问题日志,似乎尚不支持创建空间索引。

https://github.com/aspnet/EntityFrameworkCore/issues/12538

github

问题1100是支持 SQL Server 和 SQL Lite 上的空间数据类型。

于 2019-01-30T09:17:32.567 回答